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
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
Copy to ClipboardCopied!Toggle word wrapToggle overflow
如果 add 方法的调用成功,这个脚本会输出:
Attached data storage domain 'data1' to data center 'Default' (Status: maintenance).
Attached ISO storage domain 'iso1' to data center 'Default' (Status: maintenance).
Attached data storage domain 'data1' to data center 'Default' (Status: maintenance).
Attached ISO storage domain 'iso1' to data center 'Default' (Status: maintenance).
Copy to ClipboardCopied!Toggle word wrapToggle overflow