CD-ROM devices use SATA controller instead of IDE
This commit is contained in:
parent
611d51310c
commit
099215cebc
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue