本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.list_inactive_storage_pool方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.list_inactive_storage_pool方法的具体用法?Python KaresansuiVirtConnection.list_inactive_storage_pool怎么用?Python KaresansuiVirtConnection.list_inactive_storage_pool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.virt.virt.KaresansuiVirtConnection
的用法示例。
在下文中一共展示了KaresansuiVirtConnection.list_inactive_storage_pool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [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.name in active_storage_pools or \
opts.name in inactive_storage_pools):
raise KssCommandException('Storage pool does not exist. - pool=%s'
% (opts.name))
try:
self.up_progress(30)
if opts.force is True and opts.name in conn.list_active_storage_pool():
if conn.destroy_storage_pool(opts.name) is False:
raise KssCommandException("Failed to stop the storage pool. - pool=%s" \
% (opts.name))
if opts.name in conn.list_active_storage_pool():
raise KssCommandException(
"Could not delete storage pool: internal error storage pool is still active' pool=%s" \
% opts.name)
if conn.delete_storage_pool(opts.name, False) is False:
raise KssCommandException("Failed to remove the storage pool. - pool=%s" \
% (opts.name))
self.up_progress(30)
# pool check
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if opts.name in active_storage_pools or \
opts.name in inactive_storage_pools:
raise KssCommandException('Could not remove a storage pool. - pool=%s' \
% (opts.name))
# .xml
path = "%s/%s.xml" % (VIRT_STORAGE_CONFIG_DIR, opts.name)
if os.path.isfile(path) is True:
raise KssCommandException(
"Could not delete the configuration file. - pool=%s, path=%s" \
% (opts.name, path))
self.logger.info('Deleted storage pool. - pool=%s' % (opts.name))
print >>sys.stdout, _('Deleted storage pool. - pool=%s') % (opts.name)
return True
except KssCommandException, e:
raise e
finally:
conn.close()
示例2: _GET
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def _GET(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None:
return web.notfound()
self.view.host_id = host_id
# Pool
try:
kvc = KaresansuiVirtConnection()
inactive_pool = kvc.list_inactive_storage_pool()
active_pool = kvc.list_active_storage_pool()
pools = inactive_pool + active_pool
pools.sort()
self.view.pools = pools
pools_info = []
for pool in pools:
pool_obj = kvc.search_kvn_storage_pools(pool)[0]
pools_info.append(pool_obj.get_info())
if pool_obj.is_active() is True:
vols_obj = pool_obj.search_kvn_storage_volumes(kvc)
vols_info = []
for vol_obj in vols_obj:
vols_info.append(vol_obj.get_info())
finally:
kvc.close()
self.view.pools_info = pools_info
if self.is_mode_input() is True:
# .input
try:
kvc = KaresansuiVirtConnection()
already_iqn = []
for pool in pools:
pool_iqn = kvc.get_storage_pool_sourcedevicepath(pool)
if pool_iqn:
already_iqn.append(pool_iqn)
finally:
kvc.close()
network_storages = get_iscsi_cmd(self, host_id)
if network_storages is False:
self.logger.debug("Get iSCSI command failed. Return to timeout")
return web.internalerror("Internal Server Error. (Timeout)")
available_network_storages = []
for i in range(len(network_storages)):
if network_storages[i]["iqn"] not in already_iqn and network_storages[i]["activity"] == 1:
available_network_storages.append(network_storages[i])
self.view.network_storages = available_network_storages
self.view.pool_types = (STORAGE_POOL_TYPE["TYPE_DIR"], STORAGE_POOL_TYPE["TYPE_ISCSI"])
return True
示例3: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [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()
active_storage_pools = conn.list_active_storage_pool()
self.up_progress(10)
if not (opts.name in active_storage_pools or opts.name in inactive_storage_pools):
raise KssCommandException(
'Specified storage pool does not exist. - pool=%s' % opts.name)
if opts.name in active_storage_pools:
raise KssCommandException('Storage pool is already running. - pool=%s' % opts.name)
self.up_progress(10)
if conn.start_storage_pool(opts.name) is False:
raise KssCommandException(
'Failed to start storage pool. (libvirt) - pool=%s' % (opts.name))
self.up_progress(40)
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if not (opts.name in active_storage_pools):
raise KssCommandException(
'Could not start the storage pool. - pool=%s' % (opts.name))
self.logger.info('Start storage pool. - pool=%s' % (opts.name))
print >>sys.stdout, _('Start storage pool. - pool=%s') % (opts.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 list_inactive_storage_pool [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()
active_storage_pools = conn.list_active_storage_pool()
self.up_progress(10)
if not (opts.name in active_storage_pools or \
opts.name in inactive_storage_pools):
raise KssCommandException('Storage pool does not exist. - pool=%s'
% (opts.name))
self.up_progress(30)
if opts.name in conn.list_active_storage_pool():
if conn.destroy_storage_pool(opts.name) is False:
KssCommandException("Failed to stop the storage pool. - pool=%s"
% (opts.name))
else:
raise KssCommandException('Storage pool is not active. - pool=%s'
% (opts.name))
self.up_progress(30)
# check
if not (opts.name in conn.list_inactive_storage_pool()):
KssCommandException("Failed to stop the storage pool. - pool=%s"
% (opts.name))
self.logger.info('Stop storage pool. - pool=%s' % (opts.name))
print >>sys.stdout, _('Stop storage pool. - pool=%s') % (opts.name)
return True
except KssCommandException, e:
raise e
finally:
conn.close()
示例5: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [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.name in active_storage_pools or \
opts.name in inactive_storage_pools):
raise KssCommandOptException('Storage pool does not exist. - pool=%s'
% opts.name)
conn.storage_pool.set_storage_name(opts.name)
self.up_progress(10)
flag = None
if opts.enable:
flag = True
elif opts.disable:
flag = False
else:
raise KssCommandException(
'ERROR: Execution status information does not exist. enable,disable=%s,%s' \
% (str(opts.enable), str(opts.disable)))
self.up_progress(10)
if conn.autostart_storage_pool(flag) is False:
raise KssCommandException(
'Failed to autostart storage pool(libvirt). - pool=%s'
% (opts.name))
ret = conn.is_autostart_storage_pool()
if not (ret is flag):
raise KssCommandException(
'Auto-start failed to set the storage pool. - pool=%s, autostart=%s' \
% (opts.name, str(ret)))
self.up_progress(40)
if opts.enable:
self.logger.info('Set autostart storage pool. - pool=%s' % (opts.name))
print >>sys.stdout, _('Set autostart storage pool. - pool=%s') % (opts.name)
elif opts.disable:
self.logger.info('Unset autostart storage pool. - pool=%s' % (opts.name))
print >>sys.stdout, _('Unset autostart storage pool. - pool=%s') % (opts.name)
return True
finally:
conn.close()
示例6: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [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()
示例7: _PUT
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def _PUT(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None: return web.notfound()
self.view.host_id = host_id
uuid = param[1]
if not validates_storage_pool(self, uuid):
self.logger.debug("Set storage pool status failed. Did not validate.")
return web.badrequest(self.view.alert)
model = findbyhost1(self.orm, host_id)
# Pool
try:
kvc = KaresansuiVirtConnection()
inactive_pool = kvc.list_inactive_storage_pool()
active_pool = kvc.list_active_storage_pool()
pools = inactive_pool + active_pool
pools.sort()
self.view.pools = pools
pools_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
if len(pools_obj) <= 0:
self.logger.debug("Set storage pool status failed. Target storage pool not found.")
return web.notfound()
status = int(self.input.status)
if status == STORAGE_POOL_START:
storagepool_start_stop_job(self, model, pools_obj[0], 'start')
elif status == STORAGE_POOL_STOP:
if kvc.is_used_storage_pool(name=pools_obj[0].get_storage_name(),
active_only=True) is True:
self.logger.debug("Stop storage pool failed. Target storage pool is used by guest.")
return web.badrequest("Target storage pool is used by guest.")
else:
storagepool_start_stop_job(self, model, pools_obj[0], 'stop')
else:
self.logger.debug("Set storage pool status failed. Unknown status type.")
return web.badrequest()
return web.accepted()
finally:
kvc.close()
示例8: _DELETE
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def _DELETE(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None: return web.notfound()
self.view.host_id = host_id
uuid = param[1]
if not validates_storage_pool(self, uuid):
self.logger.debug("Delete storage pool failed. Did not validate.")
return web.badrequest(self.view.alert)
# Pool
try:
kvc = KaresansuiVirtConnection()
inactive_pool = kvc.list_inactive_storage_pool()
active_pool = kvc.list_active_storage_pool()
pools = inactive_pool + active_pool
pools.sort()
self.view.pools = pools
pools_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
if len(pools_obj) <= 0:
return web.notfound()
if kvc.is_used_storage_pool(pools_obj[0].get_storage_name()) is True:
self.logger.debug("Delete storage pool failed. Target storage pool is used by guest.")
return web.badrequest("Target storage pool is used by guest.")
finally:
kvc.close()
model = findbyhost1(self.orm, host_id)
if delete_storage_pool_job(self,model,pools_obj[0].get_storage_name()) is True:
self.logger.debug("Delete storage pool success. name=%s" % (pools_obj[0].get_storage_name()))
return web.accepted()
else:
self.logger.debug("Failed delete storage pool. name=%s" % (pools_obj[0].get_storage_name()))
return False
示例9: _GET
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def _GET(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None: return web.notfound()
self.view.host_id = host_id
uuid = param[1]
if not validates_storage_pool(self, uuid):
self.logger.debug("Get storage pool status failed. Did not validate.")
return web.badrequest(self.view.alert)
# Pool
try:
kvc = KaresansuiVirtConnection()
inactive_pool = kvc.list_inactive_storage_pool()
active_pool = kvc.list_active_storage_pool()
pools = inactive_pool + active_pool
pools.sort()
self.view.pools = pools
pools_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
if len(pools_obj) <= 0:
self.logger.debug("Get storage pool status failed. Target storage pool not found.")
return web.notfound()
status = STORAGE_POOL_STOP
if pools_obj[0].is_active() is True:
status = STORAGE_POOL_START
if self.__template__["media"] == 'json':
self.view.status = json_dumps(status)
else:
self.view.status = status
return True
finally:
kvc.close()
示例10: _GET
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def _GET(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None: return web.notfound()
self.view.host_id = host_id
uuid = param[1]
if not validates_storage_pool(self, uuid):
self.logger.debug("Get storage pool info failed. Did not validate.")
return web.badrequest(self.view.alert)
try:
kvc = KaresansuiVirtConnection()
inactive_pool = kvc.list_inactive_storage_pool()
active_pool = kvc.list_active_storage_pool()
pools = inactive_pool + active_pool
self.view.pools = pools
pools_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
if len(pools_obj) <= 0:
self.logger.debug("Get storage pool info failed. Target storage pool not found.")
return web.notfound()
pool_obj = pools_obj[0]
pool_info = pool_obj.get_info()
vols_info = []
if pool_obj.is_active() is True:
vols_obj = pool_obj.search_kvn_storage_volumes(kvc)
for vol_obj in vols_obj:
vols_info.append(vol_obj.get_info())
finally:
kvc.close()
self.view.pool_info = pool_info
self.view.vols_info = vols_info
return True
示例11: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [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()
示例12: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
conn.set_interface_format(opts.interface_format)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if opts.name in active_guests or opts.name in inactive_guests:
raise KssCommandException('Guest already exists. - dom=%s' % (opts.name))
self.up_progress(10)
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if not (opts.storage_pool in active_storage_pools or opts.storage_pool in inactive_storage_pools):
raise KssCommandException('Storage pool does not exist. - pool=%s' % (opts.storage_pool))
# TODO
#if conn.get_storage_volume(opts.storage_pool, opts.uuid) is None:
# raise KssCommandException('Specified storage volume does not exist. - pool=%s, vol=%s'
# % (opts.storage_pool, opts.uuid))
try:
self.up_progress(10)
if not conn.create_guest(name=opts.name,
type=opts.type.lower(),
ram=opts.mem_size,
disk=opts.disk,
disksize=opts.disk_size,
mac=opts.mac,
uuid=opts.uuid,
kernel=opts.kernel,
initrd=opts.initrd,
iso=opts.iso,
vnc=opts.vnc_port,
vcpus=opts.vcpus,
extra=opts.extra,
keymap=opts.keymap,
bus=opts.bus,
disk_format=opts.disk_format,
storage_pool=opts.storage_pool,
storage_volume=opts.storage_volume,
) is True:
raise KssCommandException('Failed to create guest. - dom=%s' % (opts.name))
except Exception, e:
self.logger.error('Failed to create guest. - dom=%s - detail %s' % (opts.name, str(e.args)))
print >>sys.stderr, _('Failed to create guest. - dom=%s - detail %s') % (opts.name, str(e.args))
raise e
self.up_progress(40)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if not (opts.name in active_guests or opts.name in inactive_guests):
raise KssCommandException('Guest OS is not recognized. - dom=%s' % (opts.name))
self.logger.info('Created guest. - dom=%s' % (opts.name))
print >>sys.stdout, 'Created guest. - dom=%s' % opts.name
return True
示例13: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [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 opts.name in active_storage_pools or opts.name in inactive_storage_pools:
raise KssCommandException('Storage pool already exists. - pool=%s' % opts.name)
try:
if opts.type == STORAGE_POOL_TYPE["TYPE_DIR"]:
if conn.create_storage_pool(opts.name, opts.type,
opts.target_path,
#allocation=opts.allocation, available=opts.available,
#capacity=opts.capacity,
target_p_group=opts.group, target_p_label=opts.label,
target_p_mode=opts.mode, target_p_owner=opts.owner,
) is False:
raise KssCommandException('Failed to create storage pools. - pool=%s' \
% opts.name)
elif opts.type == STORAGE_POOL_TYPE["TYPE_ISCSI"]:
if conn.create_storage_pool(opts.name, opts.type,
target_path="/dev/disk/by-path",
source_h_name=opts.host_name,
source_dev_path=opts.device_path,
#allocation=opts.allocation, available=opts.available,
#capacity=opts.capacity,
target_p_group=opts.group, target_p_label=opts.label,
target_p_mode=opts.mode, target_p_owner=opts.owner,
) is False:
raise KssCommandException('Failed to create storage pools. - pool=%s' \
% opts.name)
elif opts.type == STORAGE_POOL_TYPE["TYPE_FS"]:
if conn.create_storage_pool(opts.name, opts.type,
opts.target_path,
source_dev_path=opts.device_path,
#allocation=opts.allocation, available=opts.available,
#capacity=opts.capacity,
target_p_group=opts.group, target_p_label=opts.label,
target_p_mode=opts.mode, target_p_owner=opts.owner,
) is False:
raise KssCommandException('Failed to create storage pools. - pool=%s' \
% opts.name)
else:
raise KssCommandOptException('ERROR: The type that does not exist. type=%s' \
% opts.type)
self.up_progress(20)
# pool check
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if not (opts.name in active_storage_pools or opts.name in inactive_storage_pools):
raise KssCommandException(
'Failed to create storage pools. (Unexplained) - pool=%s' \
% opts.name)
self.up_progress(20)
# pool autostart check
flag = True # autostart on
if conn.autostart_storage_pool(flag) is False:
raise KssCommandException(
'Failed to autostart storage pool(libvirt). - pool=%s'
% (opts.name))
ret = conn.is_autostart_storage_pool()
if not (ret is flag):
raise KssCommandException(
'Auto-start failed to set the storage pool. - pool=%s, autostart=%s' \
% (opts.name, str(ret)))
self.logger.info('Created storage pool. - pool=%s' % (opts.name))
print >>sys.stdout, _('Created storage pool. - pool=%s') % (opts.name)
return True
except KssCommandException, e:
raise e
finally:
conn.close()
示例14: _POST
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def _POST(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None:
return web.notfound()
self.view.host_id = host_id
model = findbyhost1(self.orm, host_id)
# virt
kvc = KaresansuiVirtConnection()
try:
inactive_pool = kvc.list_inactive_storage_pool()
active_pool = kvc.list_active_storage_pool()
finally:
kvc.close()
now_pools = inactive_pool + active_pool
if self.input.pool_type == STORAGE_POOL_TYPE["TYPE_DIR"]:
if not validates_pool_dir(self, now_pools):
return web.badrequest(self.view.alert)
extra_opts = {}
if (
create_pool_dir_job(
self, model, self.input.pool_name, self.input.pool_type, self.input.pool_target_path, extra_opts
)
is True
):
self.logger.debug("Create dir storage pool success.")
return web.accepted()
else:
self.logger.debug("Failed create DIR storage pool job.")
return False
elif self.input.pool_type == STORAGE_POOL_TYPE["TYPE_ISCSI"]:
if not validates_pool_iscsi(self, now_pools):
return web.badrequest(self.view.alert)
extra_opts = {}
network_storages = get_iscsi_cmd(self, host_id)
if network_storages is False:
self.logger.debug("Get iSCSI command failed. Return to timeout")
return web.internalerror("Internal Server Error. (Timeout)")
pool_host_name = None
pool_device_path = None
for iscsi in network_storages:
if self.input.pool_target_iscsi == iscsi["iqn"]:
pool_host_name = iscsi["hostname"]
pool_device_path = iscsi["iqn"]
disk_list = iscsi["disk_list"]
break
if pool_host_name is None or pool_device_path is None:
self.logger.debug("Failed create iSCSI storage pool. Target iSCSI device not found.")
return web.badrequest()
automount_list = []
for disk in disk_list:
if is_param(self.input, "iscsi-disk-use-type-%s" % (disk["symlink_name"])):
if (
self.input["iscsi-disk-use-type-%s" % (disk["symlink_name"])] == "mount"
and disk["is_partitionable"] is False
):
if is_param(self.input, "iscsi-disk-format-%s" % (disk["symlink_name"])):
if self.input["iscsi-disk-format-%s" % (disk["symlink_name"])] == "true":
disk["is_format"] = True
automount_list.append(disk)
if (
create_pool_iscsi_job(
self,
model,
self.input.pool_name,
self.input.pool_type,
pool_host_name,
pool_device_path,
automount_list,
extra_opts,
)
is True
):
self.logger.debug("Create iSCSI storage pool success. name=%s" % (self.input.pool_name))
return web.accepted()
else:
self.logger.debug("Failed create iSCSI storage pool job. name=%s" % (self.input.pool_name))
return False
else:
self.logger.debug("Non-existent type. type=%s" % self.input.pool_type)
return web.badrequest("Non-existent type. type=%s" % self.input.pool_type)
示例15: _PUT
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_inactive_storage_pool [as 别名]
def _PUT(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None: return web.notfound()
if not validates_network_storage(self):
self.logger.debug("Network storage change status failed. Did not validate.")
return web.badrequest(self.view.alert)
host = findbyhost1(self.orm, host_id)
if is_param(self.input, "iqn"):
iqn = self.input.iqn
else:
self.logger.debug("Network storage change status failed. Target IQN not found.")
return web.badrequest()
options = {'iqn' : iqn}
job_order = 0
if is_param(self.input, "status"):
status = self.input.status
else:
self.logger.debug("Network storage change status failed. Status type not found.")
return web.badrequest()
if is_param(self.input, "host") and is_param(self.input, "port"):
host = self.input.host
port = self.input.port
else:
self.logger.debug("Network storage change status failed. Target host and port not found.")
return web.badrequest()
active_used_pool = []
inactive_used_pool = []
kvc = KaresansuiVirtConnection()
try:
dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
dev_symlink_list.sort()
symlink_regexp = re.compile("^%s/%s" % (re.escape(ISCSI_DEVICE_DIR), re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
active_pools = kvc.list_active_storage_pool()
inactive_pools = kvc.list_inactive_storage_pool()
now_pools = active_pools + inactive_pools
for pool in now_pools:
pool_type = kvc.get_storage_pool_type(pool)
if pool_type == "iscsi":
if iqn == kvc.get_storage_pool_sourcedevicepath(pool):
if pool in active_pools:
active_used_pool.append(pool)
if pool in inactive_pools:
inactive_used_pool.append(pool)
elif pool_type == "fs":
if symlink_regexp.match(kvc.get_storage_pool_sourcedevicepath(pool)):
if pool in active_pools:
active_used_pool.append(pool)
if pool in inactive_pools:
inactive_used_pool.append(pool)
if status == NETWORK_STORAGE_STOP:
for pool in active_used_pool:
if kvc.is_used_storage_pool(name=pool, active_only=True) is True:
self.logger.debug("Stop iSCSI failed. Target iSCSI is used by guest.")
return web.badrequest("Target iSCSI is used by guest.")
finally:
kvc.close()
if status == NETWORK_STORAGE_START:
network_storage_cmd = ISCSI_COMMAND_START
cmd_name = u'Start iSCSI'
jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
for pool in inactive_used_pool:
pool_cmd = dict2command(
"%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_START_STORAGE_POOL),
{"name" : pool})
pool_cmdname = "Start Storage Pool"
jobgroup.jobs.append(Job('%s command' % pool_cmdname, 1, pool_cmd))
job_order = 0
elif status == NETWORK_STORAGE_STOP:
network_storage_cmd = ISCSI_COMMAND_STOP
cmd_name = u'Stop iSCSI'
jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
for pool in active_used_pool:
pool_cmd = dict2command(
"%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_DESTROY_STORAGE_POOL),
{"name" : pool})
pool_cmdname = "Stop Storage Pool"
jobgroup.jobs.append(Job('%s command' % pool_cmdname, 0, pool_cmd))
job_order = 1
else:
return web.internalerror('Internal Server Error. (Param)')
_cmd = dict2command(
"%s/%s" % (karesansui.config['application.bin.dir'], network_storage_cmd), options)
jobgroup.jobs.append(Job('%s command' % cmd_name, job_order, _cmd))
#.........这里部分代码省略.........