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" % exadd メソッドの呼び出しが成功した場合は、スクリプトによって以下のような出力が表示されます。
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.