builder/vsphere-clone: Find the vm within the folder (#8938)
This commit is contained in:
parent
b17b211aa9
commit
c387dc2c53
|
@ -49,17 +49,18 @@ type StepCloneVM struct {
|
||||||
func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
d := state.Get("driver").(*driver.Driver)
|
d := state.Get("driver").(*driver.Driver)
|
||||||
|
vmPath := fmt.Sprintf("%s/%s", s.Location.Folder, s.Location.VMName)
|
||||||
|
|
||||||
vm, err := d.FindVM(s.Location.VMName)
|
vm, err := d.FindVM(vmPath)
|
||||||
|
|
||||||
if s.Force == false && err == nil {
|
if s.Force == false && err == nil {
|
||||||
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it", s.Location.VMName))
|
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it", vmPath))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
} else if s.Force == true && err == nil {
|
} else if s.Force == true && err == nil {
|
||||||
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", s.Location.VMName))
|
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", vmPath))
|
||||||
err := vm.Destroy()
|
err := vm.Destroy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", fmt.Errorf("error destroying %s: %v", s.Location.VMName, err))
|
state.Put("error", fmt.Errorf("error destroying %s: %v", vmPath, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,17 +94,18 @@ type StepCreateVM struct {
|
||||||
func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
d := state.Get("driver").(*driver.Driver)
|
d := state.Get("driver").(*driver.Driver)
|
||||||
|
vmPath := fmt.Sprintf("%s/%s", s.Location.Folder, s.Location.VMName)
|
||||||
|
|
||||||
vm, err := d.FindVM(s.Location.VMName)
|
vm, err := d.FindVM(vmPath)
|
||||||
|
|
||||||
if s.Force == false && err == nil {
|
if s.Force == false && err == nil {
|
||||||
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it: %v", s.Location.VMName, err))
|
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it: %v", vmPath, err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
} else if s.Force == true && err == nil {
|
} else if s.Force == true && err == nil {
|
||||||
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", s.Location.VMName))
|
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", vmPath))
|
||||||
err := vm.Destroy()
|
err := vm.Destroy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", fmt.Errorf("error destroying %s: %v", s.Location.VMName, err))
|
state.Put("error", fmt.Errorf("error destroying %s: %v", vmPath, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue