2.4. 实例:使用 Python 列出集群集合
API 类提供了访问集群集合(名为
clusters)的功能。这个集合包括了环境中的所有集群。
例 2.3. 使用 Python 列出集群集合
这个 Python 实例列出了
clusters 集合中的集群。它同时还显示了集合中的每个集群的基本信息。
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
如果环境中只包括
Default 集群,这个实例会输出以下信息:
Default (99408929-82cf-4dc7-a532-9d998063fa95)