packer-cn/builder/vsphere/iso/step_remove_cdrom.go

42 lines
922 B
Go
Raw Normal View History

package iso
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 RemoveCDRomConfig struct {
RemoveCdrom bool `mapstructure:"remove_cdrom"`
}
type StepRemoveCDRom struct {
Config *RemoveCDRomConfig
}
2018-04-25 07:22:38 -04:00
func (s *StepRemoveCDRom) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
vm := state.Get("vm").(*driver.VirtualMachine)
ui.Say("Eject CD-ROM drives...")
err := vm.EjectCdroms()
if err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
2018-05-07 03:20:27 -04:00
if s.Config.RemoveCdrom == true {
ui.Say("Deleting CD-ROM drives...")
err := vm.RemoveCdroms()
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *StepRemoveCDRom) Cleanup(state multistep.StateBag) {}