Example #1
0
    def _list_namespaces(self, cluster_id: str, shared_cluster_ids: List[str]) -> List[Dict]:
        paas_cc = PaaSCCClient(auth=ComponentAuth(get_system_token()))
        if cluster_id not in shared_cluster_ids:
            cluster = paas_cc.get_cluster_by_id(cluster_id=cluster_id)
            ns_data = paas_cc.get_cluster_namespace_list(project_id=cluster['project_id'], cluster_id=cluster_id)
            return ns_data['results'] or []

        # 共享集群获取
        ns_data = paas_cc.list_namespaces_in_shared_cluster(cluster_id)
        return ns_data['results'] or []
Example #2
0
def get_ns_id(access_token: str, project_id: str, cluster_id: str,
              namespace: str) -> int:
    """获取命名空间ID"""
    client = PaaSCCClient(ComponentAuth(access_token))
    data = client.get_cluster_namespace_list(project_id, cluster_id)
    # 匹配命名空间名称
    for ns in data.get("results") or []:
        if ns["name"] == namespace:
            return ns["id"]
    raise ValidationError(
        _("集群:{}下没有查询到命名空间:{}").format(cluster_id, namespace))
Example #3
0
 def _get_namespace_id(self):
     """获取命名空间ID,用于权限相关验证"""
     client = PaaSCCClient(
         ComponentAuth(
             access_token=self.ctx_cluster.context.auth.access_token))
     namespaces = client.get_cluster_namespace_list(
         project_id=self.ctx_cluster.project_id,
         cluster_id=self.ctx_cluster.id)
     for ns in namespaces["results"]:
         if self.namespace != ns["name"]:
             continue
         return ns["id"]
     return -1
Example #4
0
 def _list_namespaces(self, cluster_id: str) -> List[Dict]:
     paas_cc = PaaSCCClient(auth=ComponentAuth(get_system_token()))
     cluster = paas_cc.get_cluster_by_id(cluster_id=cluster_id)
     ns_data = paas_cc.get_cluster_namespace_list(
         project_id=cluster['project_id'], cluster_id=cluster_id)
     return ns_data['results']