builder/vmware: only unregister if registration success
This commit is contained in:
parent
e5ae542142
commit
ba8a0dbec0
|
@ -20,6 +20,8 @@ import (
|
|||
type stepRun struct {
|
||||
bootTime time.Time
|
||||
vmxPath string
|
||||
|
||||
registered bool
|
||||
}
|
||||
|
||||
func (s *stepRun) Run(state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -49,6 +51,8 @@ func (s *stepRun) Run(state multistep.StateBag) multistep.StepAction {
|
|||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
s.registered = true
|
||||
}
|
||||
|
||||
if err := driver.Start(vmxPath, config.Headless); err != nil {
|
||||
|
@ -91,11 +95,13 @@ func (s *stepRun) Cleanup(state multistep.StateBag) {
|
|||
}
|
||||
}
|
||||
|
||||
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
||||
if remoteDriver, ok := driver.(RemoteDriver); ok && s.registered {
|
||||
ui.Say("Unregistering virtual machine...")
|
||||
if err := remoteDriver.Unregister(s.vmxPath); err != nil {
|
||||
ui.Error(fmt.Sprintf("Error unregistering VM: %s", err))
|
||||
}
|
||||
|
||||
s.registered = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue