2.7. 实例:列出 ISO 存储域中的 ISO 文件
API 类提供了访问存储域集合(名为 storagedomains)的功能。这个集合包括了一个 files 集合来描述存储域中的文件。
例 2.6. 列出 ISO 存储域中的 ISO 文件
这个 Python 实例输出 Red Hat Enterprise Virtualization 环境中的每个 ISO 存储域中的 ISO 文件列表。
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")
storage_domains = api.storagedomains.list()
for storage_domain in storage_domains:
if(storage_domain.get_type() == "iso"):
print(storage_domain.get_name() + ":\n")
files = storage_domain.files.list()
for file in files:
print(" %s" % file.get_name())
print()
api.disconnect()
except Exception as ex:
print "Unexpected error: %s" % ex