예제 #1
0
    def get(self, request, tenant_name, *args, **kwargs):
        """
        获取团队可用的数据中心
        ---
        parameters:
            - name: tenant_name
              description: 团队名
              required: true
              type: string
              paramType: path
        """
        region_name = None
        try:
            team = console_team_service.get_tenant_by_tenant_name(tenant_name)
            if not team:
                return Response(
                    generate_result("0404", "team not found",
                                    "团队{0}不存在".format(tenant_name)))

            region_list = console_region_service.get_region_list_by_team_name(
                request, tenant_name)
            if region_list:
                region_name = region_list[0]["team_region_name"]
            else:
                regions = region_service.get_all_regions()
                if regions:
                    region_name = regions[0].region_name
            result = generate_result("0000",
                                     "success",
                                     "查询成功",
                                     bean={"region_name": region_name})
        except Exception as e:
            logger.exception(e)
            result = generate_result("9999", "system error", "系统异常")
        return Response(result)
예제 #2
0
    def get(self, request, *args, **kwargs):
        """
        同步数据中心信息
        ---
        """
        try:
            regions = region_service.get_all_regions()
            regions_info = []
            if regions:
                for r in regions:
                    clusters = cluster_service.get_cluster_by_region(
                        r.region_id)
                    if not clusters:
                        cluster_id = make_uuid()
                        cluster_alias = r.region_alias + u"-集群A"
                        cluster_name = r.region_name + "-" + "c1"
                        cluster_info = cluster_service.add_cluster(
                            r.region_id, cluster_id, cluster_name,
                            cluster_alias, True)
                        clusters = [cluster_info]
                    bean = r.to_dict()
                    bean.update({"clusters": [c.to_dict() for c in clusters]})
                    regions_info.append(bean)
            result = generate_result("0000",
                                     "success",
                                     "查询成功",
                                     list=regions_info)

        except Exception as e:
            logger.exception(e)
            result = generate_error_result()
        return Response(result)
예제 #3
0
    def get(self, request, *args, **kwargs):
        """
        同步数据中心信息
        ---
        """
        try:
            regions = region_service.get_all_regions()
            regions_info = []
            if regions:
                for r in regions:
                    bean = r.to_dict()
                    regions_info.append(bean)
            result = generate_result("0000", "success", "查询成功", list=regions_info)

        except Exception as e:
            logger.exception(e)
            result = generate_error_result()
        return Response(result)
예제 #4
0
    def get_all_region_nodes(self):
        regions = region_service.get_all_regions(True)
        # 对每个数据中心下的每个集群查询节点信息
        node_list = []
        for region in regions:

            cluster_list = cluster_service.get_cluster_by_region(
                region.region_id)
            for cluster in cluster_list:
                status, nodes = self.get_nodes(region.region_id, cluster.ID)
                if status == 200:
                    for node in nodes:
                        node["region_id"] = region.region_id
                        node["cluster_id"] = cluster.ID
                        node["region_alias"] = region.region_alias
                        node["cluster_alias"] = cluster.cluster_alias
                        node_list.append(node)

        sorted_nodes = sorted(node_list, key=lambda node: node["host_name"])
        return sorted_nodes