packer-cn/builder/vsphere/common/step_remove_floppy.go

50 lines
1.2 KiB
Go
Raw Normal View History

2020-09-18 11:09:01 -04:00
package common
import (
2018-10-31 17:42:24 -04:00
"context"
"github.com/hashicorp/packer/builder/vsphere/driver"
2018-10-31 17:42:24 -04:00
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
type StepRemoveFloppy struct {
2018-04-25 04:43:47 -04:00
Datastore string
Host string
}
2018-04-25 07:22:38 -04:00
func (s *StepRemoveFloppy) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
2020-09-23 06:00:28 -04:00
vm := state.Get("vm").(driver.VirtualMachine)
d := state.Get("driver").(driver.Driver)
2018-04-25 04:43:47 -04:00
ui.Say("Deleting Floppy drives...")
2020-09-23 06:00:28 -04:00
floppies, err := vm.FloppyDevices()
if err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
2018-05-06 17:26:04 -04:00
if err = vm.RemoveDevice(true, floppies...); err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
if UploadedFloppyPath, ok := state.GetOk("uploaded_floppy_path"); ok {
2018-04-25 04:43:47 -04:00
ui.Say("Deleting Floppy image...")
ds, err := d.FindDatastore(s.Datastore, s.Host)
if err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
if err := ds.Delete(UploadedFloppyPath.(string)); err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
state.Remove("uploaded_floppy_path")
}
return multistep.ActionContinue
}
func (s *StepRemoveFloppy) Cleanup(state multistep.StateBag) {}