Red Hat Training

A Red Hat training course is available for Red Hat Virtualization

2.6. Example: Listing the Host Collection using Python

The API class provides access to a hosts collection, named hosts. This collection contains all hosts in the environment.

Example 2.5. Listing the host collection using Python

This Python example lists the hosts in the hosts collection.
from ovirtsdk.api import API
from ovirtsdk.xml import params

try:
    api = API(url="https://HOST",
              username="USER@DOMAIN",
              password="PASS",
              ca_file="ca.crt")

    h_list = api.hosts.list()

    for h in h_list:
        print "%s (%s)" % (h.get_name(), h.get_id())

    api.disconnect()

except Exception as ex:
    print "Unexpected error: %s" % ex
In an environment where only one host, named Atlantic, has been attached the example outputs:
Atlantic (5b333c18-f224-11e1-9bdd-00163e77e2ed)