def _delete_pv(self, cluster_name, volume_name, mount_node_list, operator): kube_client = KubeClientMgr.instance().get_cluster_client(cluster_name) if kube_client is None: Log(1, 'DeleteStorageNodeWork.delete_pv get_cluster_client[%s]fail'%(cluster_name)) return Result('', INVALID_PARAM_ERR, 'cluster_name is invalid', http.BAD_REQUEST) rlt = PVDB.instance().read_pv_info_by_volume_id(cluster_name, volume_name) if not rlt.success: Log(1, 'DeleteStorageNodeWork.delete_pv read_pv_info_by_volume_id[%s][%s]fail,as[%s]'%(cluster_name, volume_name, rlt.message)) return self.delete_volume(cluster_name, volume_name, mount_node_list) pv_info = rlt.content rlt = self.delete_volume(cluster_name, volume_name, mount_node_list) if not rlt.success: Log(1, 'DeleteStorageNodeWork.delete_pv _delete_volume[%s]fail,as[%s]'%(volume_name, rlt.message)) return rlt pv_name = pv_info.get('pv_name') rlt = kube_client.delete_persistent_volume_claim(pv_info['workspace'], pv_name) if not rlt.success: Log(1, 'DeleteStorageNodeWork.delete_pv delete_persistent_volume_claim[%s]fail,as[%s]'%(pv_name, rlt.message)) rlt = kube_client.delete_persistent_volume(pv_name) if not rlt.success: Log(1, 'DeleteStorageNodeWork.delete_pv delete_persisten_tvolume[%s]fail,as[%s]'%(pv_name, rlt.message)) rlt = PVDB.instance().delete_volume(cluster_name, pv_name) if rlt.success: LogDel(3, operator, u'从集群[%s]删除容器卷[%s]'%(cluster_name, pv_name)) else: Log(1, 'DeleteStorageNodeWork.delete_pv delete_volume[%s][%s] in etcd[%s]fail,as[%s]'%(cluster_name, pv_name, rlt.message)) return rlt
def get_pv_by_group(self, group): rlt = PVDB.instance().get_pv_by_group(group) if not rlt.success: Log( 1, 'Storage.get_pv_by_group get_pv_by_group[%s]fail,as[%s]' % (group, rlt.message)) return rlt
def pvs(self, cluster): rlt = PVDB.instance().read_volume_list(cluster) if not rlt.success: Log( 1, 'Storage.get_pv_list read_volume_list[%s]fail,as[%s]' % (cluster, rlt.message)) return rlt
def get_pv_by_workspace(self, cluster, workspace): rlt = PVDB.instance().get_pv_by_workspace(cluster, workspace) if not rlt.success: Log( 1, 'Storage.get_pv_by_workspace get_pv_by_workspace[%s][%s]fail,as[%s]' % (cluster, workspace, rlt.message)) return rlt
def update_pv_info(self): if not self.volume_id: Log(1, 'AddPVWork.update_pv_info fail,as[the volume_id invalid]') return Result('', INVALID_PARAM_ERR, 'the volume_id invalid') info = {'volume_id': self.volume_id, 'access_path':self.storage_access_path, 'status':self.volume_status} rlt = PVDB.instance().update_volume(self.cluster_name, self.pv_name, info) if not rlt.success: Log(1, 'AddPVWork.update_pv_info update_volume[%s][%s]fail,as[%s]'%(self.cluster_name, self.pv_name, rlt.message)) return rlt
def workspace_pvs(self, workspace): rlt = WorkSpacedb.instance().read_workspace(workspace) if not rlt.success: Log( 1, 'Storage.workspace_volumes read_workspace[%s]fail,as[%s]' % (workspace, rlt.message)) return rlt cluster = rlt.content.get('cluster_name') rlt = PVDB.instance().get_pv_by_workspace(cluster, workspace) if not rlt.success: Log( 1, 'Storage.workspace_pvs get_pv_by_workspace[%s][%s]fail,as[%s]' % (cluster, workspace, rlt.message)) return rlt
def delete_pv(self): rlt = PVDB.instance().delete_volume(self.cluster_name, self.pv_name) if not rlt.success: Log(1, 'AddPVWork.delete_pv delete_volume[%s][%s]fail,as[%s]'%(self.cluster_name, self.pv_name, rlt.message)) return rlt
def is_volume_exist(self): if PVDB.instance().is_volume_exist(self.cluster_name, self.pv_name): return True else: Log(1, 'The volume[%s][%s] lost'%(self.cluster_name, self.pv_name)) raise InternalException("pv deleted.", TASK_CANCEL_ERR)
return Result('', INVALID_PARAM_ERR, 'capacity is invalid', http.BAD_REQUEST) #if 'read_write_mode' not in data or not data['read_write_mode']: # return Result('',INVALID_PARAM_ERR, 'read_write_mode is invalid', http.BAD_REQUEST) #if 'recovery_model' not in data or not data['recovery_model']: # return Result('',INVALID_PARAM_ERR, 'recovery_model is invalid', http.BAD_REQUEST) if 'volume_type' not in data or data['volume_type'] not in [ STORAGE_SHARE_TYPE_NFS, STORAGE_SHARE_TYPE_ISCSI ]: return Result('', INVALID_PARAM_ERR, 'volume type is invalid', http.BAD_REQUEST) if PVDB.instance().is_volume_exist(data['cluster_name'], data['pv_name']): return Result('', INVALID_PARAM_ERR, 'persistent volume name is repeat', http.BAD_REQUEST) capacity = float(data['capacity'].strip("GgMm ")) _calc = self.calc_cluster_info(data['cluster_name']) if (_calc['free'] >> 20) < capacity * 1024: return Result('', CAPACITY_LESS_THAN_REQUEST_ERR, 'Insufficient disk space') data['creator'] = args.get('passport', {}).get('username', '') rlt = StorageMgr.instance().create_persistent_volume(data) if not rlt.success: Log( 1, 'Storage.add_pv create_persistent_volume[%s][%s]fail,as[%s]' %