2018-04-25 05:23:37 -04:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
2018-04-25 07:22:38 -04:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2018-04-25 05:23:37 -04:00
|
|
|
"github.com/vmware/govmomi/vim25/types"
|
2018-04-25 07:22:38 -04:00
|
|
|
"context"
|
2018-04-25 05:23:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepRemoveCDRom struct{}
|
|
|
|
|
2018-04-25 07:22:38 -04:00
|
|
|
func (s *StepRemoveCDRom) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2018-04-25 05:23:37 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
vm := state.Get("vm").(*driver.VirtualMachine)
|
|
|
|
|
2018-04-25 04:43:47 -04:00
|
|
|
ui.Say("Deleting CD-ROM drives...")
|
2018-04-25 05:23:37 -04:00
|
|
|
devices, err := vm.Devices()
|
|
|
|
if err != nil {
|
2018-05-06 17:26:04 -04:00
|
|
|
state.Put("error", err)
|
2018-04-25 05:23:37 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
cdroms := devices.SelectByType((*types.VirtualCdrom)(nil))
|
2018-05-06 17:26:04 -04:00
|
|
|
if err = vm.RemoveDevice(true, cdroms...); err != nil {
|
|
|
|
state.Put("error", err)
|
2018-04-25 05:23:37 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepRemoveCDRom) Cleanup(state multistep.StateBag) {}
|