Hi Jason,

If you want to be able to get the name of the host running the VM, and
maybe perhaps get other properties or perform actions you would need to
work with 'hosts_service'.

Following up on your example I would add:

>>> hosts_service = connection.system_service().hosts_service()
>>> host_service = hosts_service.host_service(id=vm.host.id)
>>> host = host_service.get()
>>> print(host.name)
>>> 'host_mixed_2'

On Sat, Feb 20, 2021 at 5:28 AM <[email protected]> wrote:

> 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
> _______________________________________________
> Users mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> Privacy Statement: https://www.ovirt.org/privacy-policy.html
> oVirt Code of Conduct:
> https://www.ovirt.org/community/about/community-guidelines/
> List Archives:
> https://lists.ovirt.org/archives/list/[email protected]/message/LU7GPDJPEOOBPHRL2TQ6ZQOMJCBEX62Y/
>


-- 

Moshe Sheena

He-Him-His

Software Quality Engineer, RHV

Red Hat EMEA <https://www.redhat.com>

[email protected]    IM: msheena
<https://www.redhat.com>
_______________________________________________
Users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Privacy Statement: https://www.ovirt.org/privacy-policy.html
oVirt Code of Conduct: 
https://www.ovirt.org/community/about/community-guidelines/
List Archives: 
https://lists.ovirt.org/archives/list/[email protected]/message/CAQMSAPHNMCLEEXBHLGCHGXDAQMK5ODY/

Reply via email to