vmware / pyvmomi-community-samples

A place for community contributed samples for the pyVmomi library.
Apache License 2.0
1.02k stars 922 forks source link

How to deploy ova with mounted ISO? #684

Closed adan-zuniga closed 2 years ago

adan-zuniga commented 3 years ago

I looked at the deploy_ova.py example and it states that # CreateImportSpecParams can specify many useful things......

I'm wondering how I can specify the ISO file and floppy disk that the VM will point to once imported.

My expected outcome is to create a file that already points to different resources rather than having to reconfigure the VM after creating it.

prziborowski commented 3 years ago

Do you have an existing ISO and floppy disk on the datastore to point to? Or do you intend to upload the flp and iso files as part of the ImportVm call? If the former, then you can modify the result of the CreateImportSpec call to add a floppy/iso. The CreateImportSpecResult (object returned from CreateImportSpec) has an ImportSpec that for a VM will be VmImportSpec. The VmImportSpec contains a ConfigSpec, which is what you'd use for reconfiguring a VM. So to avoid the additional reconfigure, you'd make the changes to that ConfigSpec.

If the latter, then the ova file will contain them and I believe you'd have to upload them for the Import to work.

adan-zuniga commented 3 years ago

@prziborowski,

Thank you. I was able to deploy an OVA with an ISO mounted on the DVD drive with the following code:

vm_import_spec = cisr.importSpec
vm_config_spec = vm_import_spec.configSpec

cd_index = 0

for c, d in enumerate(vm_config_spec.deviceChange):
    if isinstance(d.device, vim.vm.device.VirtualCdrom):
        print(d)
        cd_index = c

vm_config_spec.deviceChange[cd_index].device.backing = vim.vm.device.VirtualCdrom.IsoBackingInfo()
vm_config_spec.deviceChange[cd_index].device.backing.fileName = \
    '[datastore1] ISOs/UC/Bootable_UCSInstall_UCOS_12.5.1.14900-63.sgn.iso'
vm_config_spec.deviceChange[cd_index].device.connectable.connected = True
vm_config_spec.deviceChange[cd_index].device.connectable.startConnected = True

Can you confirm that this is the proper way to do attach a file to the CD drive and that it would be the same approach to attach a file to the VirtualFloppy drive, please?

prziborowski commented 3 years ago

I think the only thing in addition for cd-rom would be what controller (IDE/SATA) it talks to. A poor, old sample: https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/cdrom_vm.py#L55