func (cmd *create) addStorage(devices object.VirtualDeviceList) (object.VirtualDeviceList, error) { if cmd.controller != "ide" { scsi, err := devices.CreateSCSIController(cmd.controller) if err != nil { return nil, err } devices = append(devices, scsi) } // If controller is specified to be IDE or if an ISO is specified, add IDE controller. if cmd.controller == "ide" || cmd.iso != "" { ide, err := devices.CreateIDEController() if err != nil { return nil, err } devices = append(devices, ide) } if cmd.disk != "" { controller, err := devices.FindDiskController(cmd.controller) if err != nil { return nil, err } ds := cmd.diskDatastore.Reference() path := cmd.diskDatastore.Path(cmd.disk) disk := devices.CreateDisk(controller, ds, path) if cmd.link { disk = devices.ChildDisk(disk) } devices = append(devices, disk) } if cmd.iso != "" { ide, err := devices.FindIDEController("") if err != nil { return nil, err } cdrom, err := devices.CreateCdrom(ide) if err != nil { return nil, err } cdrom = devices.InsertIso(cdrom, cmd.isoDatastore.Path(cmd.iso)) devices = append(devices, cdrom) } return devices, nil }
func (c *configSpec) AddDisk(ds *object.Datastore, path string) { var devices object.VirtualDeviceList controller, err := devices.CreateSCSIController("") if err != nil { panic(err) } devices = append(devices, controller) disk := devices.CreateDisk(controller.(types.BaseVirtualController), ds.Reference(), ds.Path(path)) devices = append(devices, disk) spec, err := devices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd) if err != nil { panic(err) } c.DeviceChange = append(c.DeviceChange, spec...) }
func (cmd *create) addStorage(devices object.VirtualDeviceList) (object.VirtualDeviceList, error) { if cmd.controller != "ide" { scsi, err := devices.CreateSCSIController(cmd.controller) if err != nil { return nil, err } devices = append(devices, scsi) cmd.controller = devices.Name(scsi) } // If controller is specified to be IDE or if an ISO is specified, add IDE controller. if cmd.controller == "ide" || cmd.iso != "" { ide, err := devices.CreateIDEController() if err != nil { return nil, err } devices = append(devices, ide) } if cmd.diskByteSize != 0 { controller, err := devices.FindDiskController(cmd.controller) if err != nil { return nil, err } disk := &types.VirtualDisk{ VirtualDevice: types.VirtualDevice{ Key: devices.NewKey(), Backing: &types.VirtualDiskFlatVer2BackingInfo{ DiskMode: string(types.VirtualDiskModePersistent), ThinProvisioned: types.NewBool(true), }, }, CapacityInKB: cmd.diskByteSize / 1024, } devices.AssignController(disk, controller) devices = append(devices, disk) } else if cmd.disk != "" { controller, err := devices.FindDiskController(cmd.controller) if err != nil { return nil, err } ds := cmd.diskDatastore.Reference() path := cmd.diskDatastore.Path(cmd.disk) disk := devices.CreateDisk(controller, ds, path) if cmd.link { disk = devices.ChildDisk(disk) } devices = append(devices, disk) } if cmd.iso != "" { ide, err := devices.FindIDEController("") if err != nil { return nil, err } cdrom, err := devices.CreateCdrom(ide) if err != nil { return nil, err } cdrom = devices.InsertIso(cdrom, cmd.isoDatastore.Path(cmd.iso)) devices = append(devices, cdrom) } return devices, nil }