Example #1
0
    def list(self, request, project_id):
        """get project cluster list"""
        cluster_info = self.get_cluster_list(request, project_id)
        cluster_data = cluster_info.get("results") or []
        cluster_node_map = self.cluster_has_node(request, project_id)
        # add allow delete perm
        for info in cluster_data:
            info["environment"] = cluster_env_transfer(info["environment"])
            # allow delete cluster
            allow_delete = False if cluster_node_map.get(info["cluster_id"]) else True
            info["allow"] = info["allow_delete"] = allow_delete
        perm_can_use = True if request.GET.get("perm_can_use") == "1" else False

        self.register_function_controller(cluster_data)

        cluster_results = Cluster.hook_perms(request, project_id, cluster_data, filter_use=perm_can_use)
        # add can create cluster perm for prod/test
        can_create_test, can_create_prod = self.get_cluster_create_perm(request, project_id)

        return response.Response(
            {
                "code": ErrorCode.NoError,
                "data": {"count": len(cluster_results), "results": cluster_results},
                "permissions": {
                    "test": can_create_test,
                    "prod": can_create_prod,
                    "create": can_create_test or can_create_prod,
                },
            }
        )
Example #2
0
 def get_cluster_env(self, request, project_id):
     """get cluster env map"""
     data = self.get_all_cluster(request, project_id)
     results = data.get('results') or []
     return {
         info['cluster_id']: cluster_env_transfer(info['environment']) for info in results if info.get('cluster_id')
     }
Example #3
0
    def retrieve(self, request, project_id, cluster_id):
        cluster_data = self.get_cluster(request, project_id, cluster_id)

        cluster_data["environment"] = cluster_env_transfer(cluster_data["environment"])

        # 添加功能白名单
        self.register_function_controller(cluster_data)

        return response.Response({"code": ErrorCode.NoError, "data": cluster_data})
Example #4
0
 def _cluster_id_map(self, access_token, project_id):
     clusters = node_utils.get_clusters(access_token, project_id)
     return {
         cluster["cluster_id"]: {
             "cluster_env": cluster_env_transfer(cluster["environment"]),
             "cluster_name": cluster["name"],
         }
         for cluster in clusters
     }
Example #5
0
 def get_cluster_id_info_map(self, request, project_id):
     """get cluster info map
     format: {'cluster_id': {'cluster_name': xxx, 'cluster_env': xxx}}
     """
     data = self.get_all_cluster(request, project_id)
     results = data.get('results') or []
     return {
         info['cluster_id']: {
             'cluster_env': cluster_env_transfer(info['environment']),
             'cluster_name': info['name'],
         }
         for info in results
         if info.get('cluster_id')
     }
Example #6
0
    def update(self, request, project_id, cluster_id):
        cluster_perm = Cluster(request, project_id, cluster_id)
        cluster_perm.can_edit(raise_exception=True)
        data = self.get_params(request)
        data = self.update_data(data, project_id, cluster_id, cluster_perm)
        # update cluster info
        with client.ContextActivityLogClient(
            project_id=project_id,
            user=request.user.username,
            resource_type="cluster",
            resource_id=cluster_id,
        ).log_modify():
            cluster_info = self.update_cluster(request, project_id, cluster_id, data)
        # render environment for frontend
        cluster_info["environment"] = cluster_env_transfer(cluster_info["environment"])

        return response.Response(cluster_info)
Example #7
0
    def retrieve(self, request, project_id, cluster_id):
        cluster_data = self.get_cluster(request, project_id, cluster_id)

        cluster_data["environment"] = cluster_env_transfer(cluster_data["environment"])

        return response.Response({"code": ErrorCode.NoError, "data": cluster_data})
Example #8
0
 def list(self, request, project_id):
     """获取集群列表"""
     clusters = self.get_cluster_list(request, project_id)
     for info in clusters.get("results") or []:
         info["environment"] = cluster_env_transfer(info["environment"])
     return Response(clusters)