Ejemplo n.º 1
0
def get_ingress_list(request, namespace):
    kd_logger.info('call get_ingress_list request.path : %s , namespace : %s' %
                   (request.path, namespace))
    ingress_detail_info = KRM.get_ingress_detail_info(namespace)
    if ingress_detail_info['code'] == RETU_INFO_ERROR:
        kd_logger.error('call get_ingress_list query k8s data error : %s' %
                        ingress_detail_info['msg'])
        return generate_failure(ingress_detail_info['msg'])

    retu_data = []
    for item in ingress_detail_info['data']['items']:
        record = {}
        retu_data.append(record)
        record['Name'] = item['metadata']['name']

        try:
            record['Ingress'] = []
            for ing in item['status']['loadBalancer']['ingress']:
                record['Ingress'].append(ing['ip'])
        except:
            record['Ingress'] = ['<None>']

        try:
            record['Rules'] = get_ingress_detail_host_info(
                item['spec']['rules'])
        except:
            record['Rules'] = []

        record['CreationTime'] = trans_time_str(
            item['metadata']['creationTimestamp'])
        record['DetailInfo'] = trans_obj_to_easy_dis(item)

    kd_logger.debug('call get_ingress_list query k8s data : %s' % retu_data)
    kd_logger.info('call get_ingress_list query k8s data successful')
    return generate_success(data=retu_data)
Ejemplo n.º 2
0
def execute_clusterinfo_request(data_dict):
    retu_obj = {}
    for m, data in data_dict.items():
        # 对获取到的influx数据进行筛选,只保留有用的数据
        retu_data = filter_valid_data(data)
        if retu_data['code'] != RETU_INFO_SUCCESS:
            return generate_failure(retu_data['msg'])
        retu_obj[m] = retu_data['data']
    return generate_success(data=trans_struct_to_easy_dis(retu_obj))
Ejemplo n.º 3
0
def get_k8soverview_info(request, namespace):
    retu_data = {
        'pod': get_overview_k8s_pod_info(namespace),
        'rc': get_overview_k8s_rc_info(namespace),
        'service': get_overview_k8s_service_info(namespace),
        'node': get_overview_k8s_node_info(namespace)
    }
    kd_logger.info(
        'call get_overview_k8s_rc_info query k8s overview info : %s' %
        retu_data)
    return generate_success(data=retu_data)
Ejemplo n.º 4
0
def filter_valid_data(influxdb_data_dict):
    try:
        columns = influxdb_data_dict['results'][0]['series'][0]['columns']
        series_values = influxdb_data_dict['results'][0]['series'][0]['values']

        retu_data = []
        for item in series_values:
            # item是一个list,item[0]为时间戳,item[1]为value
            if item[1] != None:
                retu_data.append(item)
        return generate_success(data=retu_data)
    except Exception as reason:
        return generate_failure(traceback.format_exc())
Ejemplo n.º 5
0
def get_pod_list(request, namespace):
    kd_logger.info('call get_pod_list request.path : %s , namespace : %s' %
                   (request.path, namespace))
    pod_detail_info = KRM.get_pod_detail_info(namespace)
    if pod_detail_info['code'] == RETU_INFO_ERROR:
        kd_logger.error('call get_pod_list query k8s data error : %s' %
                        pod_detail_info['msg'])
        return generate_failure(pod_detail_info['msg'])

    retu_data = []
    for item in pod_detail_info['data']['items']:
        record = {}
        retu_data.append(record)
        record['Name'] = item['metadata']['name']
        record['CreationTime'] = trans_time_str(
            item['metadata']['creationTimestamp'])
        record['Node'] = item['spec'].get('nodeName', '<None>')
        record['DetailInfo'] = trans_obj_to_easy_dis(item)

        containerStatuses = item['status'].get('containerStatuses', [])
        total = len(containerStatuses)
        running = 0
        for cItem in containerStatuses:
            if cItem['state'].get('running') != None:
                running += 1
        record['Ready'] = '%s / %s' % (running, total)

        if total == running:
            record['Status'] = 'Running'
        else:
            #TODO:此处需要测试
            statusArr = []
            for cItem in containerStatuses:
                statusArr.append(
                    cItem['state'][cItem['state'].keys()[0]]['reason'])
            record['Status'] = '{ %s }' % str(',').join(set(statusArr))

        restartCountArr = []
        for cItem in containerStatuses:
            restartCountArr.append(cItem['restartCount'])
        record['Restarts'] = sum(restartCountArr)

    kd_logger.debug('call get_pod_list query k8s data : %s' % retu_data)
    kd_logger.info('call get_pod_list query k8s data successful')
    return generate_success(data=retu_data)
Ejemplo n.º 6
0
def get_rc_list(request, namespace):
    kd_logger.info('call get_rc_list request.path : %s , namespace : %s' %
                   (request.path, namespace))
    rc_detail_info = KRM.get_rc_detail_info(namespace)
    if rc_detail_info['code'] == RETU_INFO_ERROR:
        kd_logger.error('call get_rc_list query k8s data error : %s' %
                        rc_detail_info['msg'])
        return generate_failure(rc_detail_info['msg'])

    retu_data = []
    for item in rc_detail_info['data']['items']:
        record = {}
        retu_data.append(record)

        record['Name'] = item['metadata']['name']
        record['Desired'] = item['spec']['replicas']
        record['Current'] = item['status']['replicas']  #TODO:Current暂时这样取值
        record['CreationTime'] = trans_time_str(
            item['metadata']['creationTimestamp'])
        record['DetailInfo'] = trans_obj_to_easy_dis(item)

        container_arr = []
        image_arr = []
        for cItem in item['spec']['template']['spec']['containers']:
            container_arr.append(cItem['name'])
            image_arr.append(cItem['image'])
        record['Containers'] = str(',').join(container_arr)
        record['Images'] = str(',').join(image_arr)

        if not item['spec'].get('selector'):
            record['Selector'] = '<None>'
        else:
            selector_info_arr = []
            for k, v in item['spec']['selector'].iteritems():
                selector_info_arr.append('%s=%s' % (k, v))
            record['Selector'] = str(',').join(selector_info_arr)

    kd_logger.debug('call get_rc_list query k8s data : %s' % retu_data)
    kd_logger.info('call get_rc_list query k8s data successful')
    return generate_success(data=retu_data)
Ejemplo n.º 7
0
def get_service_list(request, namespace):
    kd_logger.info('call get_service_list request.path : %s , namespace : %s' %
                   (request.path, namespace))
    service_detail_info = KRM.get_service_detail_info(namespace)
    if service_detail_info['code'] == RETU_INFO_ERROR:
        kd_logger.error('call get_service_list query k8s data error : %s' %
                        service_detail_info['msg'])
        return generate_failure(service_detail_info['msg'])

    retu_data = []
    for item in service_detail_info['data']['items']:
        record = {}
        retu_data.append(record)

        record['Name'] = item['metadata']['name']
        record['ClusterIP'] = item['spec']['clusterIP']
        record[
            'ExternalIP'] = '<None-IP>'  #TODO:mini的测试暂时没有这个东西,这里暂时填充 <none-IP>
        record['CreationTime'] = trans_time_str(
            item['metadata']['creationTimestamp'])
        record['DetailInfo'] = trans_obj_to_easy_dis(item)

        ports_info_arr = []
        for cItem in item['spec']['ports']:
            ports_info_arr.append('%s/%s' % (cItem['port'], cItem['protocol']))
        record['Ports'] = str(',').join(ports_info_arr)

        if not item['spec'].get('selector'):
            record['Selector'] = '<None>'
        else:
            selector_info_arr = []
            for k, v in item['spec']['selector'].iteritems():
                selector_info_arr.append('%s=%s' % (k, v))
            record['Selector'] = str(',').join(selector_info_arr)

    kd_logger.debug('call get_service_list query k8s data : %s' % retu_data)
    kd_logger.info('call get_service_list query k8s data successful')
    return generate_success(data=retu_data)
Ejemplo n.º 8
0
def get_mytask_graph(request):
    kd_logger.info('call get_mytask_graph')
    url = 'http://%s:%s/k8s/api/v1/namespaces/mytaskgraph' % (
        settings.BDMS_IP, settings.BDMS_PORT)  #任务运行网络图 rest api
    try:
        req = requests.Session()
        r = req.get(url)
        if r.status_code == 200:
            kd_logger.debug('get my task graph data success ')
            dic = json.loads(r.text)
            all_task = []
            data = {}
            nodes = []
            edges = []
            task_info = dic['task_info']
            task_process = []

            #处理节点数据及颜色信息
            for i in task_info:
                try:
                    id = "%s" % i["id"]
                    if dic['task_process'][id]['status'] == 1:
                        nodes.append({
                            "id": id,
                            "label": i["exec_txt"],
                            "color": "#A9A9A9"
                        })
                    if dic['task_process'][id]['status'] == 2:
                        nodes.append({
                            "id": id,
                            "label": i["exec_txt"],
                            "color": "#2db7f5"
                        })
                    if dic['task_process'][id]['status'] == 3:
                        nodes.append({
                            "id": id,
                            "label": i["exec_txt"],
                            "color": "#0000FF"
                        })
                    if dic['task_process'][id]['status'] == 4 and dic[
                            'task_process'][id]['result'] == 1:
                        nodes.append({
                            "id": id,
                            "label": i["exec_txt"],
                            "color": "#87d068"
                        })
                    if dic['task_process'][id]['status'] == 4 and dic[
                            'task_process'][id]['result'] == 2:
                        nodes.append({
                            "id": id,
                            "label": i["exec_txt"],
                            "color": "#F50"
                        })
                except Exception, e:
                    nodes.append({
                        "id": id,
                        "label": i["exec_txt"],
                        "color": "#A9A9A9"
                    })
            # 处理依赖关系
            for depen in dic['task_info']:
                if depen['input']:
                    for detal in depen['input']:
                        edges.append({"from": detal, "to": depen['id']})
            data["nodes"] = nodes
            data["edges"] = edges
            return generate_success(data=data)
        else: