def filter_namespaces(self, cluster_id: str): paas_cc = PaaSCCClient(auth=ComponentAuth(self.access_token)) ns_data = paas_cc.get_cluster_namespace_list( project_id=self.project_id, cluster_id=cluster_id) ns_list = ns_data['results'] or [] # 过滤掉 k8s 系统和 bcs 平台使用的命名空间 return [ns for ns in ns_list if ns['name'] not in K8S_PLAT_NAMESPACE]
def list_namespaces(self, request, project_id, cluster_id): resp = paas_cc.get_cluster_namespace_list(request.user.token.access_token, project_id, cluster_id) if resp.get('code') != ErrorCode.NoError: logger.error('get namespaces error, %s', resp.get('message')) return Response({'namespaces': []}) namespaces = resp.get('data', {}).get('results', []) return Response({'namespaces': namespaces})
def get_cluster_namespaces(access_token, project_id, cluster_id): resp = paas_cc.get_cluster_namespace_list(access_token, project_id, cluster_id, desire_all_data=1) if resp.get('code') != ErrorCode.NoError: raise error_codes.APIError( _("获取集群下命名空间信息异常,{}").format(resp.get('message'))) return resp['data'].get('results') or []
def get_cluster_namespace(request, project_id, cluster_id): """获取集群下namespace的数量""" resp = paas_cc.get_cluster_namespace_list( request.user.token.access_token, project_id, cluster_id, limit=constants.ALL_LIMIT ) if resp.get("code") != ErrorCode.NoError: logger.error(u"获取命名空间数量异常,当前集群ID: %s, 详情: %s" % (cluster_id, resp.get("message"))) return {} return resp.get("data") or {}
def get_cluster_namespaces(access_token, project_id, cluster_id): ns_resp = paas_cc.get_cluster_namespace_list(access_token, project_id, cluster_id, desire_all_data=True) if ns_resp.get('code') != ErrorCode.NoError: raise error_codes.APIError( f'get cluster namespace error, {ns_resp.get("message")}') data = ns_resp.get('data') or {} return data.get('results') or []
def get_namespaces_by_cluster_id(access_token, project_id, cluster_id): resp = paas_cc.get_cluster_namespace_list(access_token, project_id, cluster_id, desire_all_data=True) if resp.get('code') != ErrorCode.NoError: raise error_codes.APIError( f"get namespace error, {resp.get('message')}") return resp.get('data', {}).get('results', [])
def get_cluster_ns_list(self): cluster_ns_info = paas_cc.get_cluster_namespace_list( self.access_token, self.project_id, self.cluster_id, desire_all_data=True ) if cluster_ns_info.get('code') != ErrorCode.NoError: self.update_cluster_status(status=CommonStatus.RemoveFailed) raise error_codes.APIError(cluster_ns_info.get('message')) data = cluster_ns_info.get('data', {}).get('results') or [] # 删除命名空间权限记录 for info in data: perm_client = Namespace(self.request, self.project_id, info["id"]) perm_client.delete() return [int(info['id']) for info in data]
def register_ns(log): # 添加default命名空间 # 如果存在则跳过 resp = paas_cc.get_cluster_namespace_list( log.token, log.project_id, log.cluster_id, desire_all_data=True ) ns_name_list = [ info["name"] for info in resp.get("data", {}).get("results") or [] if info.get("name") ] if "default" not in ns_name_list: # 获取项目编排类型,只有为k8s时,才会执行注册操作 resp = paas_cc.get_project(log.token, log.project_id) data = resp.get("data", {}) if data.get("kind") == 1: register_default_ns(log.token, log.operator, log.project_id, data.get("english_name"), log.cluster_id)
def _get_cluster_namespace_list(access_token, project_id, cluster_id): return paas_cc.get_cluster_namespace_list(access_token, project_id, cluster_id, desire_all_data=True)