2.5. 示例:使用 Python 列出逻辑网络集合

API 类提供了访问逻辑网络集合(名为 networks)的功能。这个集合包括了环境中的所有逻辑网络。

例 2.4. 使用 Python 列出逻辑网络集合

这个 Python 示例列出了 networks 集合中的逻辑网络。它同时还显示了集合中的每个网络的基本信息。
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
如果环境中只包括默认的管理网络,这个示例会输出以下信息:
ovirtmgmt (00000000-0000-0000-0000-000000000009)