Show Table of Contents
2.12. 示例:使用 Python 激活存储域
一旦把存储域添加到 Red Hat Virtualization,并把它们附加到一个数据中心,您需要把它们激活后才可以使用。
例 2.11. 使用 Python 激活存储域
这个 Python 示例激活了一个名为
data1 的数据存储域和一个名为 iso1 的 ISO 存储域。这两个存储域都被附加到 Default 数据中心中。激活操作是通过存储域的 activate 方法实现的。
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 = dc.storagedomains.get(name="data1")
sd_iso = dc.storagedomains.get(name="iso1")
try:
sd_data.activate()
print "Activated data storage domain '%s' in data center '%s' (Status: %s)." %
(sd_data.get_name(), dc.get_name, sd_data.get_status().get_state())
except Exception as ex:
print "Activating data storage domain in data center failed: %s." % ex
try:
sd_iso.activate()
print "Activated ISO storage domain '%s' in data center '%s' (Status: %s)." %
(sd_iso.get_name(), dc.get_name, sd_iso.get_status().get_state())
except Exception as ex:
print "Activating ISO storage domain in data center failed: %s." % ex
api.disconnect()
except Exception as ex:
print "Unexpected error: %s" % ex
如果
activate 请求成功,脚本会输出:
Activated data storage domain 'data1' in data center 'Default' (Status: active). Activated ISO storage domain 'iso1' in data center 'Default' (Status: active).
请注意:
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.