Destroy machine + remove data dir when machine id is set to empty value

This commit is contained in:
sophia 2021-12-13 15:17:15 -06:00 committed by Paul Hinze
parent 29d005dd72
commit 31e57414b4
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 8 additions and 2 deletions

View File

@ -34,8 +34,12 @@ func (m *Machine) ID() (id string, err error) {
// SetID implements core.Machine
func (m *Machine) SetID(value string) (err error) {
m.machine.Id = value
return m.SaveMachine()
if value == "" {
return m.Destroy()
} else {
m.machine.Id = value
return m.SaveMachine()
}
}
func (m *Machine) Box() (b core.Box, err error) {

View File

@ -3,6 +3,7 @@ package core
import (
"context"
"fmt"
"os"
"strings"
"sync"
"time"
@ -218,6 +219,7 @@ func (t *Target) Destroy() (err error) {
_, err = t.Client().DeleteTarget(t.ctx, &vagrant_server.DeleteTargetRequest{
Target: t.Ref().(*vagrant_plugin_sdk.Ref_Target),
})
os.RemoveAll(t.dir.DataDir().String())
return
}