本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.get_storage_volume方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.get_storage_volume方法的具体用法?Python KaresansuiVirtConnection.get_storage_volume怎么用?Python KaresansuiVirtConnection.get_storage_volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.virt.virt.KaresansuiVirtConnection
的用法示例。
在下文中一共展示了KaresansuiVirtConnection.get_storage_volume方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_volume [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
self.up_progress(10)
if not (opts.pool_name in active_storage_pools or \
opts.pool_name in inactive_storage_pools):
raise KssCommandException('Storage pool does not exist. - pool=%s'
% opts.name)
pool_dir = conn.get_storage_pool_targetpath(opts.pool_name)
#image_path = os.path.realpath("%s/%s/images/%s.img" % (pool_dir, opts.name, opts.name))
#vol = conn.get_storage_volume_symlink(image_path)
#if not vol:
# raise KssCommandException("Storage volume could not be found.")
#else:
# vol = vol[0]
if conn.get_storage_volume(opts.pool_name, opts.name) is None:
raise KssCommandException(
'Specified storage volume does not exist. - pool=%s, vol=%s'
% (opts.pool_name, opts.name))
try:
self.up_progress(30)
if conn.delete_storage_volume(opts.pool_name,
opts.name,
opts.use,
True) is False:
KssCommandException("Failed to destroy storage volume. (libvirt)- pool=%s, vol=%s" \
% (opts.pool_name, opts.name))
self.up_progress(30)
self.logger.info('Deleted storage volume. - pool=%s, vol=%s' % (opts.pool_name, opts.name))
print >>sys.stdout, _('Deleted storage volume. - pool=%s, vol=%s') % (opts.pool_name, opts.name)
return True
except KssCommandException, e:
raise e
finally:
conn.close()
示例2: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_volume [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
try:
self.up_progress(10)
progresscb = None
if opts.debug is True:
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
vol_obj = conn.get_storage_volume(opts.orig_pool, opts.orig_volume)
if vol_obj is None:
raise KssCommandException(
'Specified storage volume does not exist. - pool=%s, vol=%s'
% (opts.orig_pool, opts.orig_volume))
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if not (opts.dest_pool in active_storage_pools or \
opts.dest_pool in inactive_storage_pools):
raise KssCommandException('Destination storage pool does not exist. - pool=%s'
% (opts.dest_pool))
vol_info = vol_obj.info()
if vol_info[0] != 0:
raise KssCommandException(
'Specified storage volume does not "file" type. - pool=%s, vol=%s'
% (opts.orig_pool, opts.orig_volume))
filesize = vol_info[1] / (1024 * 1024) # a unit 'MB'
target_path = conn.get_storage_pool_targetpath(opts.dest_pool)
if chk_create_disk(target_path, filesize) is False:
raise KssCommandException(
'Destination storage pool shortage capacity. - pool=%s'
% (opts.dest_pool))
if conn.replicate_storage_volume(opts.orig_name,
opts.orig_pool,
opts.orig_volume,
opts.dest_name,
opts.dest_pool,
opts.dest_volume,
progresscb) is False:
raise KssCommandException(_("Failed to copy storage volume."))
self.up_progress(40)
self.logger.info('Replicate storage volume. - orig_pool=%s, orig_vol=%s, dest_pool=%s' % (opts.orig_pool, opts.orig_volume, opts.dest_pool))
print >>sys.stdout, _('Replicate storage volume. - orig_pool=%s, orig_vol=%s, dest_pool=%s' % (opts.orig_pool, opts.orig_volume, opts.dest_pool))
return True
except Exception, e:
raise e
finally:
conn.close()
示例3: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_volume [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
try:
#inactive_storage_pools = conn.list_inactive_storage_pool()
inactive_storage_pools = []
active_storage_pools = conn.list_active_storage_pool()
if not (opts.pool_name in active_storage_pools or \
opts.pool_name in inactive_storage_pools):
raise KssCommandException('Storage pool does not exist. Alternatively, the storage pool is not started. - pool=%s'
% opts.pool_name)
if conn.get_storage_volume(opts.pool_name, opts.volume_name) is not None:
raise KssCommandException(
'We already have a storage volume. - pool=%s, vol=%s'
% (opts.pool_name, opts.volume_name))
pool_obj = conn.search_kvn_storage_pools(opts.pool_name)[0]
pool_info = pool_obj.get_info()
if not pool_info['allocation'] or pool_info['allocation'] == 0:
storage_volume_allocation_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
else:
storage_volume_allocation_max_size = long(pool_info['allocation']) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
if pool_info['type'] == 'dir' or pool_info['type'] == 'fs':
storage_volume_allocation_max_size = long(pool_info["available"]) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
if not pool_info['capacity'] or pool_info['capacity'] == 0:
storage_volume_capacity_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
else:
storage_volume_capacity_max_size = long(pool_info['capacity']) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
if opts.allocation < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_allocation_max_size < opts.allocation:
raise KssCommandException('Allocation "%s%s" is out of available range. available=%s-%s%s'
% (opts.allocation, opts.unit, STORAGE_VOLUME_SIZE_MIN_LENGTH, storage_volume_allocation_max_size, opts.unit))
if opts.capacity < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_capacity_max_size < opts.capacity:
raise KssCommandException('Capacity "%s%s" is out of available range. available=%s-%s%s'
% (opts.capacity, opts.unit, STORAGE_VOLUME_SIZE_MIN_LENGTH, storage_volume_capacity_max_size, opts.unit))
if conn.create_storage_volume(opts.name,
opts.pool_name,
opts.format,
use=opts.use,
volume_name=opts.volume_name,
capacity=opts.capacity,
allocation=opts.allocation,
c_unit=opts.unit,
t_p_owner=opts.permission_owner,
t_p_group=opts.permission_group,
t_p_mode=opts.permission_mode,
) is False:
raise KssCommandException('Failed to create storage volume. (libvirt) - pool=%s, vol=%s'
% (opts.pool_name, opts.volume_name))
self.up_progress(40)
vol_path = conn.get_storage_volume_path(opts.pool_name, opts.volume_name)
if vol_path is None:
raise KssCommandException(
'Could not get the normal storage pool or storage volume. - pool=%s, vol=%s' \
% (opts.pool, opts.volume_name))
if os.path.isfile(vol_path) is False:
raise KssCommandException(
'File does not exist in the path of a storage volume. - pool=%s, vol=%s' \
% (opts.pool, opts.volume_name))
vol_obj = conn.get_storage_volume(opts.pool_name, opts.volume_name)
if vol_obj is None:
raise KssCommandException(
'Could not get the normal storage pool or storage volume. - pool=%s, vol=%s' \
% (opts.pool, opts.volume_name))
vol_link = "%s/%s" % (pool_info['target']['path'], vol_obj.name())
if os.path.islink(vol_link) is False:
raise KssCommandException(
'Symbolic link does not exist in the path of a storage volume. - pool=%s, vol=%s' \
% (opts.pool, opts.volume_name))
self.logger.info('Created storage volume. - vol=%s' % (opts.volume_name))
print >>sys.stdout, _('Created storage volume. - vol=%s') % (opts.volume_name)
return True
except KssCommandException, e:
raise e
finally:
conn.close()
示例4: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_volume [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
conn.set_domain_name(opts.name)
self.up_progress(10)
active_storage_pools = conn.list_active_storage_pool()
if opts.pool not in active_storage_pools:
raise KssCommandException('Storage pool does not exist. - pool=%s' % opts.name)
if not conn.get_storage_volume(opts.pool, opts.volume):
raise KssCommandException('Storage volume does not exist. - pool=%s, volume=%s' % (opts.name, opts.volume))
self.up_progress(10)
if opts.type.lower() == 'iscsi':
real_volume_path = conn.get_storage_volume_iscsi_rpath_bystorage(opts.pool, opts.volume)
if not real_volume_path:
raise KssCommandException('Failure get iSCSI volume real path. - pool=%s, volume=%s' % (opts.name, opts.volume))
format = None
disk_type = 'block'
elif opts.type.lower() == 'file':
real_volume_path = "%s/%s/%s/%s.img" % \
(conn.get_storage_pool_targetpath(opts.pool),
opts.name,
DISK_USES["DISK"],
opts.volume)
format = opts.format
disk_type = 'file'
else:
raise KssCommandException('Unknown Storage Type. type=%s' % opts.type)
if opts.target:
target = opts.target
else:
target = conn.guest.next_disk_target(opts.bus)
self.up_progress(10)
already_disks = conn.guest.get_disk_info()
for already_disk in already_disks:
if already_disk['type'] == 'file':
already_path = already_disk['source']['file']
elif already_disk['type'] == 'block':
already_path = already_disk['source']['dev']
else:
already_path = ''
if already_path == real_volume_path:
raise KssCommandException('Source disk is already used. path=%s' % real_volume_path)
if opts.format is None:
format = get_disk_img_info(real_volume_path)['file_format']
conn.guest.append_disk(real_volume_path,
target,
bus=opts.bus,
disk_type=disk_type,
driver_name=None,
driver_type=format,
)
self.up_progress(30)
finally:
conn.close()
self.logger.info('Added disk device. - dom=%s target=%s path=%s' \
% (opts.name, target, real_volume_path))
print >>sys.stdout, 'Added disk device. - dom=%s target=%s path=%s' \
% (opts.name, target, real_volume_path)
return True