2.5. Example: Listing the Logical Networks Collection using Python

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

Example 2.4. Listing the logical networks collection using Python

This Python example lists the logical networks in the networks collection. It also outputs some basic information about each network 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")

    n_list = api.networks.list()

    for n in n_list:
        print "%s (%s)" % (n.get_name(), n.get_id())
    
    api.disconnect()
    
except Exception as ex:
    print "Unexpected error: %s" % ex
In an environment where only the default management network exists, the example outputs:
ovirtmgmt (00000000-0000-0000-0000-000000000009)