def check_valid(self): """ # 检查数据 """ try: if not StorageNodeDB.instance().is_app_node_exist(self.cluster_name, self.ip): return Result('', INVALID_PARAM_ERR, 'mount host is invalid') if self.veclient is None: self.veclient = VespaceMgr.instance().get_cluster_client(self.cluster_name) if not self.veclient.test(): return Result('', INIT_VESPACE_CLIENT_FAILERR, 'init vespace client fail.') kube_client = KubeClientMgr.instance().get_cluster_client(self.cluster_name) if kube_client is None: Log(1, 'AddPVWork.check_valid get_cluster_client[%s]fail'%(self.cluster_name)) return Result('', INVALID_PARAM_ERR, 'cluster_name is invalid') else: self.kubeclient = kube_client if self.recovery_model not in ['Retain', 'Recycle', 'Delete']: self.recovery_model = 'Delete' except InternalException,e: Log(1,"AddPVWork.check_valid except[%s]"%(e.value)) return Result("AddPVWork",e.errid,e.value)
def _sync_volume_info(self, cluster_name, filtername=''): rlt = VolumeDB.instance().read_volume_list(cluster_name) if not rlt.success: Log( 1, 'Storage.volumes read_volume_list[%s]fail,as[%s]' % (cluster_name, rlt.message)) return rlt volumes = rlt.content if len(volumes) == 0: Log(3, 'volumes[%s]no volume exist in etcd.') return Result([]) cluster_id = volumes[0].get('cluster_id') client = VespaceMgr.instance().get_cluster_client(cluster_name) rlt = client.get_volume_list(cluster_id, filtername) if not rlt.success: Log( 1, 'Storage.volumes get_volume_list[%s]fail,as[%s]' % (cluster_name, rlt.message)) return rlt tmp = {} for volume in rlt.content.get('List', []): tmp[volume['name']] = volume if not tmp: Log(3, 'volumes[%s]no volume exist in server.') return Result([]) arr = [] for volume in volumes: volume_name = volume['name'] if volume_name not in tmp: Log( 1, 'The volume[%s][%s] not exist in server' % (cluster_name, volume_name)) VolumeDB.instance().delete_volume(cluster_name, volume['volume_id']) continue volume['status'] = tmp[volume_name].get('status', '-') volume['flag'] = tmp[volume_name].get('flag', '-') volume['capacity_num'] = tmp[volume_name].get('capacity', 0) volume['mounted'] = tmp[volume_name].get('mounted', []) volume['accesspath'] = tmp[volume_name].get('accesspath', []) volume['controllerhosts'] = tmp[volume_name].get( 'controllerhosts', {}).get('default', []) arr.append(volume) return Result(arr)
def check_valid(self): """ # 检查数据 """ try: if self.client is None: self.client = VespaceMgr.instance().get_cluster_client( self.cluster_name) if not (self.client and self.client.test()): return Result('', INIT_VESPACE_CLIENT_FAILERR, 'init vespace client fail.') if StorageNodeDB.instance().is_node_exist(self.cluster_name, self.ip): return Result('', STORAGE_NODE_EXIST_ALREADY_ERR, 'The node is added.') except InternalException, e: Log(1, "AddStorageNodeWork.check_valid except[%s]" % (e.value)) return Result("AddStorageNodeWork", e.errid, e.value)
def check_valid(self): """ # 检查数据 """ try: if self.client is None: self.client = VespaceMgr.instance().get_cluster_client( self.cluster_name) if not (self.client and self.client.test()): return Result('', INIT_VESPACE_CLIENT_FAILERR, 'init vespace client fail.') if StoregeClusterDB.instance().get_cluster_num( self.cluster_name) <= 1: return Result('', LAST_CLUSTER_CANNOT_DELETE_ERR, 'The last cluster can not be delete') except InternalException, e: Log(1, "DeleteStorageWork.check_valid except[%s]" % (e.value)) return Result("DeleteStorageWork", e.errid, e.value)
def check_valid(self): """ # 检查数据 """ try: if self.client is None: self.client = VespaceMgr.instance().get_cluster_client(self.cluster_name) if not (self.client and self.client.test()): return Result('', INIT_VESPACE_CLIENT_FAILERR, 'init vespace client fail.') rlt = StorageNodeDB.instance().read_node_info(self.cluster_name, self.ip) if not rlt.success: Log(1, 'DeleteStorageNodeWork.check_valid read_node_info[%s][%s]fail,as[%s]'%(self.cluster_name, self.ip, rlt.message)) return Result('', STORAGE_NODE_NOT_EXIST_ERR, 'The node is not exist.' ) self.store_api_port = rlt.content.get('store_api_port', STOREGE_HOST_PORT) self.app_api_port = rlt.content.get('app_api_port', APPLICATION_HOST_PORT) except InternalException,e: Log(1,"DeleteStorageNodeWork.check_valid except[%s]"%(e.value)) return Result("DeleteStorageNodeWork",e.errid,e.value)
def _get_disk_info(self, cluster_name, node_info): client = VespaceMgr.instance().get_cluster_client(cluster_name) rlt = client.get_storage_host_info(node_info['cluster_id'], node_info['domain_name'], node_info['ip'], node_info['store_api_port']) if not rlt.success: Log( 1, 'Storage.get_storage_host_info [%s][%s]fail,as[%s]' % (node_info['cluster'], node_info['ip'], rlt.message)) return rlt disk_list = (rlt.content.get('Disk') or {}).get('Dbi', []) engine = rlt.content.get('Engine') if isinstance(engine, dict): DataDevices = engine.get('DataDev') or [] CacheDevices = engine.get('CacheDev') or [] else: DataDevices = [] CacheDevices = [] data = {} for device in DataDevices: device['engine'] = 'data' data[device['Device']] = device for device in CacheDevices: device['engine'] = 'cache' data[device['Device']] = device for disk in disk_list: disk_path = disk['Path'] if disk_path in data: disk.update(data[disk_path]) disk['added'] = True else: disk['added'] = False return Result(disk_list)
if 'ip' not in data or not data['ip']: return Result('', INVALID_PARAM_ERR, 'ip is invalid', http.BAD_REQUEST) cluster_name = data['cluster_name'] ip = data['ip'] rlt = StoregeClusterDB.instance().get_cluster_info(cluster_name) if not rlt.success: Log( 1, 'Storage.add_node get_cluster_info[%s][%s]fail,as[%s]' % (cluster_name, ip, rlt.message)) return Result('', FAIL, 'The cluster not exist') cluster_id = rlt.content.get('cluster_id') client = VespaceMgr.instance().get_cluster_client(cluster_name) rlt = client.add_host(cluster_id, DEFAULT_STORAGE_DOMAIN, ip, HOST_TYPE_STOREGE) if not rlt.success: Log( 1, 'Storage.add_node [%s][%s]fail,as[%s]' % (cluster_name, ip, rlt.message)) return rlt host_info = { 'cluster': cluster_name, 'cluster_id': cluster_id, 'domain_name': DEFAULT_STORAGE_DOMAIN, 'ip': ip, 'store_api_port': rlt.content.get('port') }