Hi,
I suggest sending questions to ovirt-users so others could find
answers as well as to allow others who might know better chime in as
well
As to your question, something like this works for me:
vms_service = connection.system_service().vms_service()
vm_service = vms_service.vm_service('vm-id')
affinity_labels = vm_service.affinity_labels_service().list()
for affinity_label in affinity_labels:
hosts = connection.follow_link(affinity_label.hosts)
for host in hosts:
print(connection.follow_link(host).name)
(I am not sure where exactly the problem is in your code)
On Mon, Feb 15, 2021 at 2:32 PM Lavi Bochnik <lavi.bochnik(a)gmail.com> wrote:
Hello Benny,
Not sure if I can email you directly, but you helped me once.
I have some VM's which are labeled with specific affinity.
Via API I would like to get a VM affinity label, in order to later get the hosts defined
under that affinity.
I tried many ways as:
vm = vms_service.list(search='<vm_name>')[0]
print(vm.affinity_labels)
or:
for affinity_label in affinity_labels:
print("%s:" % affinity_label.name)
for vm_link in connection.follow_link(affinity_label.vms):
vm = connection.follow_link(vm_link)
print(" - %s" % vm.name)
Getting an href error: Error: The URL
'/ovirt-engine/api/affinitylabels/0d68b36e-455a-4054-9958-0503d54a18db/vms'
isn't compatible with the base URL of the connection
Href's are looking fine, as:
In [77]: for x in affinity_labels_service.list():
...: print(x.href)
/ovirt-engine/api/affinitylabels/0d68b36e-455a-4054-9958-0503d54a18db
/ovirt-engine/api/affinitylabels/862df742-fdc4-4eb0-933c-027729e2187d
/ovirt-engine/api/affinitylabels/686d96a6-0c9c-4fb7-b453-a79cbd48790b
/ovirt-engine/api/affinitylabels/6d42df24-c4b1-45e7-8029-0ce26b8ed73d
Or this:
1 for affinity_label in affinity_labels:
----> 2 for h in connection.follow_link(affinity_label.hosts):
3 print(h)
4
5
/usr/local/lib64/python3.6/site-packages/ovirtsdk4/__init__.py in follow_link(self, obj)
782 raise Error(
783 "The URL '%s' isn't compatible with the base URL
of the "
--> 784 "connection" % href
785 )
786
Error: The URL
'/ovirt-engine/api/affinitylabels/0d68b36e-455a-4054-9958-0503d54a18db/hosts'
isn't compatible with the base URL of the connection
Not clear what is the right way to get a VM affinity hosts list.
Thanks,
Lavi