I am having some issues figuring out how to get a list of VMs and the host that they are
running on.
I seem to be able to get a reference to the host object, but can't see how to print
the name of the host.
See the below code snippet:
#! /usr/bin/python
import ovirtsdk4 as sdk
import ovirtsdk4.types as types
connection = sdk.Connection(
url='https:/<redacted>:443/ovirt-engine/api',
username='admin@internal',
password='<redacted>',
ca_file='ovirt-engine_ca.crt',
)
vms_service = connection.system_service().vms_service()
vms = vms_service.list()
for vm in vms:
print("VM.name = " + vm.name)
vm_service = vms_service.vm_service(vm.id)
#vm = vm_service.get()
print(vm.status)
if vm.name == 'vmexample':
print("HERE")
print(vm.host)
print(vm.host.name)
connection.close()
OUTPUT:
VM.name = vmexample
up
HERE
<ovirtsdk4.types.Host object at 0x7f5ca250e810>
None
What am I missing?
Thanks,
Jason