packer-cn/iso/step_add_cdrom.go

40 lines
973 B
Go
Raw Normal View History

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"
"fmt"
"context"
)
type CDRomConfig struct {
ISOPaths []string `mapstructure:"iso_paths"`
}
type StepAddCDRom struct {
Config *CDRomConfig
}
2018-04-25 07:22:38 -04:00
func (s *StepAddCDRom) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
vm := state.Get("vm").(*driver.VirtualMachine)
2018-05-06 17:26:04 -04:00
ui.Say("Adding CD-ROM drives...")
if err := vm.AddSATAController(); err != nil {
state.Put("error", fmt.Errorf("error adding SATA controller: %v", err))
return multistep.ActionHalt
}
for _, path := range s.Config.ISOPaths {
if err := vm.AddCdrom(path); err != nil {
state.Put("error", fmt.Errorf("error adding a cdrom: %v", err))
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *StepAddCDRom) Cleanup(state multistep.StateBag) {}