2.6. 示例:使用 Python 列出主机集合
API 类提供对名为 hosts 的主机集合的访问。此集合包含环境中的所有主机。
例 2.5. 使用 Python 列出主机集合
此 Python 示例列出了主机集合中
的主机。
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
在一个只有一个主机的环境中,名为
Atlantic,并附加了示例输出:
Atlantic (5b333c18-f224-11e1-9bdd-00163e77e2ed)