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
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
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)
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)