Example #1
0
 def compose_inst_info(self, all_inst_list, cluster_env_map):
     """组装实例信息
     """
     ret_data = {}
     for info in all_inst_list:
         conf = json.loads(info.config)
         metadata = conf.get("metadata", {})
         key_name = (metadata.get("namespace"), metadata.get("name"))
         labels = metadata.get("labels")
         backend_status = "BackendNormal"
         oper_type_flag = ""
         if not info.is_bcs_success:
             if info.oper_type == "create":
                 backend_status = "BackendError"
             else:
                 oper_type_flag = info.oper_type
         cluster_id = labels.get("io.tencent.bcs.clusterid")
         muster_id = labels.get("io.tencent.paas.templateid")
         cluster_name_env_map = cluster_env_map.get(cluster_id) or {}
         ret_data[key_name] = {
             "from_platform": True,
             "id": info.id,
             "name": metadata.get("name"),
             "namespace": metadata.get("namespace"),
             "namespace_id": info.namespace,
             "create_at": info.created,
             "update_at": info.updated,
             "backend_status": backend_status,
             "backend_status_message": _("请求失败,已通知管理员!"),
             "status": "Unready",
             "status_message": _("请点击查看详情"),
             "creator": info.creator,
             "category": REVERSE_CATEGORY_MAP[info.category],
             "oper_type": info.oper_type,
             "oper_type_flag": oper_type_flag,
             "cluster_id": cluster_id,
             "pod_count": "0/0",
             "build_instance": 0,
             "instance": 0,
             "muster_id": muster_id,
             "muster_name": self.get_muster_info(muster_id),
             "cluster_name": cluster_name_env_map.get("cluster_name"),
             "cluster_env": cluster_name_env_map.get("cluster_env"),
             "environment": cluster_name_env_map.get("cluster_env_str")
         }
         annotations = metadata.get('annotations') or {}
         ret_data[key_name].update(get_instance_version(
             annotations, labels))
     return ret_data
Example #2
0
    def compose_inst_info(self, all_inst_list, cluster_env_map):
        """组装实例信息
        """
        ret_data = {}
        category_data = {"application": {}, "deployment": {}}
        for info in all_inst_list:
            conf = json.loads(info.config)
            metadata = conf.get("metadata", {})
            key_name = (metadata.get("namespace"), metadata.get("name"))
            labels = metadata.get("labels") or {}
            item = {
                "name": metadata.get("name"),
                "namespace": metadata.get("namespace"),
                "cluster_id": labels.get("io.tencent.bcs.clusterid"),
            }

            if info.category == "application":
                category_data["application"][key_name] = item
            else:
                category_data["deployment"][key_name] = item
            backend_status = "BackendNormal"
            oper_type_flag = ""
            if not info.is_bcs_success:
                if info.oper_type == "create":
                    backend_status = "BackendError"
                else:
                    oper_type_flag = info.oper_type
            cluster_id = labels.get("io.tencent.bcs.clusterid")
            muster_id = labels.get("io.tencent.paas.templateid")
            cluster_name_env_map = cluster_env_map.get(cluster_id) or {}
            ret_data[key_name] = {
                "from_platform": True,
                "id": info.id,
                "name": metadata.get("name"),
                "namespace": metadata.get("namespace"),
                "namespace_id": info.namespace,
                "create_at": info.created,
                "update_at": info.updated,
                "backend_status": backend_status,
                "backend_status_message": _("请求失败,已通知管理员!"),
                "application_status": "Deploying",
                "deployment_status": "Deploying",
                "application_status_message": "",
                "deployment_status_message": "",
                "creator": info.creator,
                "category": info.category,
                "oper_type": info.oper_type,
                "oper_type_flag": oper_type_flag,
                "cluster_id": cluster_id,
                "cluster_name": cluster_name_env_map.get("cluster_name"),
                "cluster_env": cluster_name_env_map.get("cluster_env"),
                "environment": cluster_name_env_map.get("cluster_env_str"),
                "task_group_count": "0/0",
                "build_instance": 0,
                "instance": 0,
                "muster_id": muster_id,
                "muster_name": self.get_muster_info(muster_id)
            }
            annotations = metadata.get("annotations") or {}
            ret_data[key_name].update(
                utils.get_instance_version(annotations, labels))
        return ret_data, category_data