diff --git a/driver/vm.go b/driver/vm.go index bfa642b1a..3b43069e9 100644 --- a/driver/vm.go +++ b/driver/vm.go @@ -446,12 +446,12 @@ func (vm *VirtualMachine) AddCdrom(isoPath string) error { if err != nil { return err } - ide, err := devices.FindIDEController("") + sata, err := vm.FindSATAController() if err != nil { return err } - cdrom, err := devices.CreateCdrom(ide) + cdrom, err := vm.CreateCdrom(sata) if err != nil { return err } diff --git a/driver/vm_cdrom.go b/driver/vm_cdrom.go new file mode 100644 index 000000000..0ce45a34c --- /dev/null +++ b/driver/vm_cdrom.go @@ -0,0 +1,48 @@ +package driver + +import ( + "github.com/vmware/govmomi/vim25/types" + "errors" +) + +func (vm *VirtualMachine) AddSATAController() error { + sata := &types.VirtualAHCIController{} + return vm.addDevice(sata) +} + +func (vm *VirtualMachine) FindSATAController() (*types.VirtualAHCIController, error) { + l, err := vm.Devices() + if err != nil { + return nil, err + } + + c := l.PickController((*types.VirtualAHCIController)(nil)) + if c == nil { + return nil, errors.New("no available SATA controller") + } + + return c.(*types.VirtualAHCIController), nil +} + +func (vm *VirtualMachine) CreateCdrom(c *types.VirtualAHCIController) (*types.VirtualCdrom, error) { + l, err := vm.Devices() + if err != nil { + return nil, err + } + + device := &types.VirtualCdrom{} + + l.AssignController(device, c) + + device.Backing = &types.VirtualCdromAtapiBackingInfo{ + VirtualDeviceDeviceBackingInfo: types.VirtualDeviceDeviceBackingInfo{}, + } + + device.Connectable = &types.VirtualDeviceConnectInfo{ + AllowGuestControl: true, + Connected: true, + StartConnected: true, + } + + return device, nil +} diff --git a/iso/step_add_cdrom.go b/iso/step_add_cdrom.go index 1dd7f6e17..387e76a3f 100644 --- a/iso/step_add_cdrom.go +++ b/iso/step_add_cdrom.go @@ -25,6 +25,11 @@ func (s *StepAddCDRom) Run(state multistep.StateBag) multistep.StepAction { vm := state.Get("vm").(*driver.VirtualMachine) ui.Say("Adding CDRoms...") + 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))