Show Table of Contents
2.3. 示例:使用 Python 列出数据中心集合
API 类提供了访问数据中心集合(名为 datacenters)的功能。这个集合包括了环境中的所有数据中心。
例 2.2. 使用 Python 列出数据中心集合
这个 Python 示例列出了
datacenters 集合中的所有数据中心。它同时还显示了集合中的每个数据中心的基本信息。
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")
dc_list = api.datacenters.list()
for dc in dc_list:
print "%s (%s)" % (dc.get_name(), dc.get_id())
api.disconnect()
except Exception as ex:
print "Unexpected error: %s" % ex
如果环境中只包括
Default 数据中心,而且它还没有被激活,这个示例会输出以下信息:
Default (d8b74b20-c6e1-11e1-87a3-00163e77e2ed)

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.