本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.export_guest方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.export_guest方法的具体用法?Python KaresansuiVirtConnection.export_guest怎么用?Python KaresansuiVirtConnection.export_guest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.virt.virt.KaresansuiVirtConnection
的用法示例。
在下文中一共展示了KaresansuiVirtConnection.export_guest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import export_guest [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
try:
src_pool = conn.get_storage_pool_name_bydomain(opts.name, "os")
if not src_pool:
raise KssCommandException("Source storage pool not found. domain=%s" % (opts.name))
if conn.get_storage_pool_type(src_pool) == 'dir':
raise KssCommandException("Storage pool type 'dir' is not. domain=%s" % (opts.name))
src_path = conn.get_storage_pool_targetpath(src_pool[0])
self.domain_dir = "%s/%s" % (src_path, opts.name,)
if os.path.isdir(self.domain_dir) is False:
raise KssCommandException(
'domain directory is not found or not directory. - %s' % (self.domain_dir))
# Model
virt_uuid = conn.domname_to_uuid(opts.name)
model = findby1uniquekey(self.kss_session, virt_uuid)
if not model:
raise KssCommandException("Export data does not exist in the database.")
database = {}
database['attribute'] = model.attribute
database['hypervisor'] = model.hypervisor
database['icon'] = model.icon
database['name'] = model.name
database['notebook'] = {"title" : model.notebook.title,
"value" : model.notebook.value,
}
tags = []
for _tag in model.tags:
tags.append(_tag.name)
database['tags'] = ",".join(tags)
database['uniq_key'] = model.uniq_key
# Snapshot
snapshots = []
kvs = KaresansuiVirtSnapshot(readonly=False)
try:
guest_id = model.id
snapshot_list = kvs.listNames(opts.name)[opts.name]
if len(snapshot_list) > 0:
for snapshot in snapshot_list:
s_model = s_findbyname_guestby1(self.kss_session, snapshot, guest_id)
if s_model is not None:
name = s_model.name
title = s_model.notebook.title
value = s_model.notebook.value
snapshots.append({"name":name, "title":title, "value":value,})
except:
raise KssCommandException("Cannot fetch the information of snapshots correctly.")
kvs.finish()
# Pool
target_dir = ""
if opts.pool:
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if not (opts.pool in active_storage_pools or opts.pool in inactive_storage_pools):
raise KssCommandException('Target storage pool does not exist. - pool=%s' % (opts.pool))
pool = conn.search_kvn_storage_pools(opts.pool)
storage_info = pool[0].get_info()
if storage_info["type"] == "dir" and storage_info["target"]["path"] != "":
target_dir = storage_info["target"]["path"]
else:
raise KssCommandException("Target storage pool type is not 'dir'. pool=%s" % (opts.pool))
elif opts.dir:
target_dir = opts.dir
self.up_progress(10)
progresscb = None
if opts.verbose:
try:
from karesansui.lib.progress import ProgressMeter
progresscb = ProgressMeter(command_object=self)
except:
pass
else:
try:
from karesansui.lib.progress import ProgressMeter
progresscb = ProgressMeter(command_object=self,quiet=True)
except:
pass
if opts.title[0:4] == "b64:":
title = base64_decode(opts.title[4:])
else:
title = opts.title
uuid = StrFromUUID(GenUUID())
conn.export_guest(uuid=uuid,
name=opts.name,
#.........这里部分代码省略.........