Red Hat Training

A Red Hat training course is available for Red Hat Virtualization

2.4. Example: Listing the Cluster Collection using Python

The API class provides a clusters collection, named clusters. This collection contains all clusters in the environment.

Example 2.3. Listing the clusters collection using Python

This Python example lists the clusters in the clusters collection. It also outputs some basic information about each cluster in the 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")
      
    c_list = api.clusters.list()       
    
    for c in c_list:
        print "%s (%s)" % (c.get_name(), c.get_id())

    api.disconnect()

except Exception as ex:
    print "Unexpected error: %s" % ex
In an environment where only the Default cluster exists, the example outputs:
Default (99408929-82cf-4dc7-a532-9d998063fa95)