Show Table of Contents
2.11. 示例:使用 Python 为数据中心附加存储域
在把存储域添加到 Red Hat Virtualization 后,需要把它们附加到数据中心并进行激活,然后才可以被使用。
例 2.10. 使用 Python 为数据中心附加存储域
这个 Python 示例把一个名为
data1 的数据存储域和一个名为 iso1 的 ISO 存储域附加到 default 数据中心中。这个附加的操作是通过数据中心的 storagedomains 集合的 add 方法实现的。
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 = api.datacenters.get(name="Default")
sd_data = api.storagedomains.get(name="data1")
sd_iso = api.storagedomains.get(name="iso1")
try:
dc_sd = dc.storagedomains.add(sd_data)
print "Attached data storage domain '%s' to data center '%s' (Status: %s)." %
(dc_sd.get_name(), dc.get_name, dc_sd.get_status().get_state())
except Exception as ex:
print "Attaching data storage domain to data center failed: %s." % ex
try:
dc_sd = dc.storagedomains.add(sd_iso)
print "Attached ISO storage domain '%s' to data center '%s' (Status: %s)." %
(dc_sd.get_name(), dc.get_name, dc_sd.get_status().get_state())
except Exception as ex:
print "Attaching ISO storage domain to data center failed: %s." % ex
api.disconnect()
except Exception as ex:
print "Unexpected error: %s" % ex
如果
add 方法的调用成功,这个脚本会输出:
Attached data storage domain 'data1' to data center 'Default' (Status: maintenance). Attached ISO storage domain 'iso1' to data center 'Default' (Status: maintenance).
请注意:
status 的值代表了存储域仍然需要被激活。

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.