2020-02-12 11:31:46 -05:00
|
|
|
//go:generate struct-markdown
|
|
|
|
//go:generate mapstructure-to-hcl2 -type RemoveCDRomConfig
|
|
|
|
|
2018-04-25 05:23:37 -04:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
2018-10-31 17:42:24 -04:00
|
|
|
"context"
|
2020-02-14 11:42:29 -05:00
|
|
|
|
2020-01-07 19:59:31 -05:00
|
|
|
"github.com/hashicorp/packer/builder/vsphere/driver"
|
2018-10-31 17:42:24 -04:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2018-04-25 05:23:37 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
)
|
|
|
|
|
2020-02-04 14:25:45 -05:00
|
|
|
type RemoveCDRomConfig struct {
|
2020-02-12 11:31:46 -05:00
|
|
|
// Remove CD-ROM devices from template. Defaults to `false`.
|
2020-02-04 14:25:45 -05:00
|
|
|
RemoveCdrom bool `mapstructure:"remove_cdrom"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type StepRemoveCDRom struct {
|
|
|
|
Config *RemoveCDRomConfig
|
|
|
|
}
|
2018-04-25 05:23:37 -04:00
|
|
|
|
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-10-21 03:47:35 -04:00
|
|
|
ui.Say("Eject CD-ROM drives...")
|
|
|
|
err := vm.EjectCdroms()
|
2018-04-25 05:23:37 -04:00
|
|
|
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
|
|
|
|
}
|
2018-05-07 03:20:27 -04:00
|
|
|
|
2020-02-05 10:25:49 -05:00
|
|
|
if s.Config.RemoveCdrom == true {
|
2020-02-04 14:25:45 -05:00
|
|
|
ui.Say("Deleting CD-ROM drives...")
|
|
|
|
err := vm.RemoveCdroms()
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 10:25:49 -05:00
|
|
|
return multistep.ActionContinue
|
2018-04-25 05:23:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepRemoveCDRom) Cleanup(state multistep.StateBag) {}
|