| 309 | } |
| 310 | |
| 311 | func addISO(ctx context.Context, newVM vmConfig, vm *object.VirtualMachine, dss *object.Datastore) { |
| 312 | devices, err := vm.Device(ctx) |
| 313 | if err != nil { |
| 314 | log.Fatalf("Unable to read devices from VM configuration\n%v", err) |
| 315 | } |
| 316 | |
| 317 | ide, err := devices.FindIDEController("") |
| 318 | if err != nil { |
| 319 | log.Fatalf("Unable to find IDE device from VM configuration\n%v", err) |
| 320 | } |
| 321 | |
| 322 | cdrom, err := devices.CreateCdrom(ide) |
| 323 | if err != nil { |
| 324 | log.Fatalf("Unable to create new CDROM device\n%v", err) |
| 325 | } |
| 326 | |
| 327 | var add []types.BaseVirtualDevice |
| 328 | add = append(add, devices.InsertIso(cdrom, dss.Path(fmt.Sprintf("%s/%s", *newVM.vmFolder, path.Base(*newVM.path))))) |
| 329 | |
| 330 | log.Infof("Adding ISO to the Virtual Machine") |
| 331 | |
| 332 | if err := vm.AddDevice(ctx, add...); err != nil { |
| 333 | log.Fatalf("Unable to add new CD-ROM device to VM configuration\n%v", err) |
| 334 | } |
| 335 | } |