Exemplo n.º 1
0
 def cluster_masters(self, request, project_id, cluster_id):
     self.can_view_cluster(request, project_id, cluster_id)
     ip_only = request.query_params.get('ip_only')
     # get master ip
     master_ips = self.get_master_ips(request, project_id, cluster_id)
     if ip_only == 'true':
         return response.Response([{'inner_ip': ip} for ip in master_ips])
     # get cc hosts
     cc_host_info = cmdb.CMDBClient(request).get_cc_hosts()
     # compose the data
     masters = []
     for info in cc_host_info:
         # may be many eths
         convert_host = convert_mappings(
             cluster_constants.CCHostKeyMappings, info)
         ip_list = convert_host.get('inner_ip', '').split(',')
         if not ip_list:
             continue
         for ip in ip_list:
             if ip not in master_ips:
                 continue
             # NOTE: 添加master后,默认master agent状态是正常的
             convert_host["agent"] = AGENT_NORMAL_STATUS
             masters.append(convert_host)
             break
     return response.Response(masters)
Exemplo n.º 2
0
def get_cmdb_hosts(username: str, cc_app_id: int, host_property_filter: Dict) -> List:
    """
    根据指定条件获取 CMDB 主机信息,包含字段映射等转换
    """
    hosts = []
    for info in cc.HostQueryService(username, cc_app_id, host_property_filter=host_property_filter).fetch_all():
        convert_host = convert_mappings(CCHostKeyMappings, info)
        convert_host["agent"] = AGENT_NORMAL_STATUS
        hosts.append(convert_host)

    return hosts
Exemplo n.º 3
0
def get_event(access_token: str, project_id: str, validated_data: dict, clusters: dict) -> Tuple[list, int]:
    results = []
    count = 0

    query = convert_mappings(EVENT_RESULT_MAPPINGS, validated_data, reversed=True)
    for env in settings.BCS_EVENT_ENV:
        result = _get_event(access_token, project_id, env, query)
        for res in result.data:
            # 转换变量
            res = convert_mappings(EVENT_RESULT_MAPPINGS, res)

            # 补充集群名称
            cluster_id = res.get('cluster_id')
            cluster_info = clusters.get(cluster_id) or {}
            res['cluster_name'] = cluster_info.get('name', '')

            results.append(res)
        count += result.count

    return results, count
Exemplo n.º 4
0
def get_cmdb_hosts(username, cc_app_id_list, host_property_filter):
    hosts = []
    for app_id in cc_app_id_list:
        resp = cc.list_biz_hosts(username, int(app_id), host_property_filter=host_property_filter)
        if resp.get("data"):
            hosts = resp["data"]
            break
    cluster_masters = []
    for info in hosts:
        convert_host = convert_mappings(CCHostKeyMappings, info)
        convert_host["agent"] = AGENT_NORMAL_STATUS
        cluster_masters.append(convert_host)

    return cluster_masters
Exemplo n.º 5
0
 def get_images(self, params):
     query = convert_mappings(self.ResultMappings, params, reversed=True)
     query["access_token"] = self.request.user.token.access_token
     query['project_code'] = ''
     return api.get_public_image_list(query)