def delete(self, request, project_id, namespace_id, is_validate_perm=True): """删除集群 """ access_token = request.user.token.access_token # 检查权限 perm = bcs_perm.Namespace(request, project_id, namespace_id) perm.can_delete(raise_exception=is_validate_perm) access_token = request.user.token.access_token ns_result = paas_cc.get_namespace(access_token, project_id, namespace_id) if ns_result.get('code') != 0: raise error_codes.APIError.f(ns_result.get('message', '')) ns_data = ns_result.get('data') cluster_id = ns_data.get('cluster_id') name = ns_data.get('name') project_kind = request.project.kind if project_kind == K8S_PROJECT_KIND: client = K8SClient(access_token, project_id, cluster_id, env=None) elif project_kind == MESOS_PROJECT_KIND: client = MesosClient(access_token, project_id, cluster_id, env=None) else: raise ValidationError("项目编排类型不正确") # 删除 namespace result = client.delete_namespace(name) if result.get('code') != 0: raise error_codes.ComponentError.f( "删除Namespace失败,%s, 请联系管理员解决" % result.get('message')) result = paas_cc.delete_namespace( access_token, project_id, namespace_id) if result.get('code') != 0: raise error_codes.APIError.f(result.get('message')) # 删除资源 perm.delete() return response.Response(result)
def delete_ns_by_bcs(self, client, name): result = client.delete_namespace(name) if result.get('code') != 0: raise error_codes.ComponentError.f( _("创建Namespace失败,{}").format(result.get('message')))
def delete_ns_by_bcs(self, client, name): result = client.delete_namespace(name) if result.get('code') != 0: raise error_codes.ComponentError.f("创建Namespace失败,%s, 请联系管理员解决" % result.get('message'))