Beispiel #1
0
def fast_execute_sql(request):
    bk_biz_id = request.POST.get('bk_biz_id', 8)
    ip_list = request.POST.getlist('ips', [])

    bk_biz_id = int(bk_biz_id)

    client = get_client_by_request(request)
    params = {'bk_biz_id': bk_biz_id}
    account_result = client.job.get_own_db_account_list(params)
    db_account_id = account_result['data'][0]['db_account_id']

    script_content = 'show databases;'
    params = {
        'bk_biz_id':
        bk_biz_id,
        'script_content':
        str(base64.b64encode(script_content.encode("utf-8")), "utf-8"),
        'db_account_id':
        db_account_id,
        'ip_list': []
    }
    if ip_list:
        for ip in ip_list:
            params['ip_list'].append({'bk_cloud_id': 0, 'ip': ip})
    result = get_client_by_request(request).job.fast_execute_sql(params)
    return JsonResponse({'result': True, 'data': result})
Beispiel #2
0
def home(request):
    """
    首页
    """
    result = get_client_by_request(request).cc.search_business()
    biz_list = result['data']['info']
    # 部门
    params = {'no_page': True}
    result = get_client_by_request(request).usermanage.list_departments(params)
    dept_list = result['data']
    return render(request, 'exam/host.html', {
        'biz_list': biz_list,
        'dept_list': dept_list
    })
Beispiel #3
0
def search_server_by_server(request):
    filter_obj = json.loads(request.body)
    client = get_client_by_request(request)
    result = search_host(client, filter_obj)
    if not result["result"]:
        return render_json({"result": False, "data": []})
    return_data = []
    for i in result["data"]["info"]:
        # 过滤掉windows
        # if i["host"]["bk_os_type"] != "1":
        #     continue
        one_obj = {
            "app_name": i["biz"][0]["bk_biz_name"],
            "ip_address": i["host"]["bk_host_innerip"],
            "host_name": i["host"]["bk_host_name"],
            "os_name": i["host"]["bk_os_name"],
            "cloud_name": i["host"]["bk_cloud_id"][0]["bk_inst_name"],
            "cloud_id": i["host"]["bk_cloud_id"][0]["bk_inst_id"],
            "app_id": i["biz"][0]["bk_biz_id"],
            # "cpu_usage": "--",
            # "mem_usage": "--",
            # "disk_usage": "--",
        }
        # one_obj["is_add"] = Servers.objects.filter(app_id=one_obj["app_id"], ip_address=one_obj["ip_address"],
        #                                            cloud_id=one_obj["cloud_id"], is_deleted=False).exists()
        return_data.append(one_obj)
    return render_json({"result": True, "data": return_data})
Beispiel #4
0
def search_host_by_biz(request):
    """
    查询主机根据业务
    """
    res = {'code': 0, 'message': '操作成功', 'data': []}
    client = get_client_by_request(request)
    where = {"page": {"start": 0, "limit": 200}}
    result = client.cc.search_business(where)

    if not result.get('result', False):
        return JsonResponse(res, safe=False)

    biz = {}
    for val in result['data']['info']:
        temp = gethosts(client, val['bk_biz_id'])
        if len(temp) > 0:
            biz[val['bk_biz_id']] = {
                'id': val['bk_biz_id'],
                'name': val['bk_biz_name'],
                'children': temp
            }

    res['data'] = biz

    return JsonResponse(res, safe=False)
Beispiel #5
0
def execute(request):
    """执行任务"""

    biz_id = request.POST.get("biz_id")
    script_type = request.POST.get("script_type")
    script_param = request.POST.get("script_param", "")
    ips = request.POST.getlist("ips[]")

    if biz_id:
        biz_id = int(biz_id)

    if script_type:
        script_type = int(script_type)

    try:
        script_content = Script.objects.get(id=script_type).script
    except Script.DoesNotExist:
        return render_json({"result": False, "message": "script not exist!"})

    client = get_client_by_request(request)

    task = run_script.delay(client, biz_id, script_content, script_param, ips)

    opt = Operation.objects.create(biz=biz_id,
                                   script=Script.objects.get(id=script_type),
                                   machine_numbers=len(ips),
                                   celery_id=task.id,
                                   argument=script_param,
                                   user=request.user.username)

    return render_json({
        "result": True,
        "data": opt.celery_id,
        "message": "success"
    })
Beispiel #6
0
def get_history(request):
    myclient = get_client_by_request(request)
    myclient.set_bk_api_ver('v2')
    biz_id = request.GET.get('biz_id')

    begintime = request.GET.get('begintime')
    endtime = request.GET.get('endtime')

    begin = datetime.fromtimestamp(int(begintime) / 1000)
    end = datetime.fromtimestamp(int(endtime) / 1000)

    historys = OptHistory.objects.filter(bk_biz_id=biz_id).filter(opt_at__gte=begin).filter(opt_at__lte=end). \
        order_by('-opt_at')

    list = []
    for history in historys:
        list.append({
            "operator": history.operator,
            "log": history.log,
            "ip_list": history.ip_list,
            "bk_biz_name": history.bk_biz_name,
            "job_status": history.job_status,
            "opt_at": history.opt_at.strftime("%Y-%m-%d %H:%M:%S"),
            "job_id": history.job_id
        })

    return render_json({'result': True, 'data': list})
 def delete_host_lock(cls, request):
     """根据主机 ID 删除主机锁,多个以逗号分隔"""
     id_list = request.GET.get('id_list')
     client = get_client_by_request(request)
     kwargs = {"id_list": [int(i) for i in id_list.split(',')]}
     info = client.cc.delete_host_lock(kwargs)
     return JsonResponse(info)
    def list_set_template(cls, request):
        """根据业务 id 查询集群模板"""
        bk_biz_id = request.GET.get('bk_biz_id', 2)
        # set_template_ids = request.GET.get('set_template_ids', [12])
        client = get_client_by_request(request)
        kwargs = {
            "bk_biz_id": bk_biz_id,
            # "set_template_ids": set_template_ids  # 指定模版id,则获取该id的模板信息
        }

        info = client.cc.list_set_template(
            kwargs)  # 接口文档有误,bk_module_id不传获取不到实例
        """
        返回结果
        id	int	集群模板 ID
        name	array	集群模板名称
        bk_biz_id	int	业务 ID
        version	int	集群模板版本
        creator	string	创建者
        modifier	string	最后修改人员
        create_time	string	创建时间
        last_time	string	更新时间
        bk_supplier_account	string	开发商账号
        """
        return JsonResponse({"data": info['data']})
Beispiel #9
0
def search_host_by_set(request):
    """
    获取主机
    :param request:
    :return:
    """
    filter_obj = json.loads(request.body)
    client = get_client_by_request(request)
    result = get_host_by_condition(client, request.user.username, filter_obj)
    if not result["result"]:
        return render_json({"result": False, "data": []})
    return_data = []
    for i in result["data"]["info"]:
        if i["host"]["bk_os_type"] != "1":
            continue
        one_obj = {
            "ip_address": i["host"]["bk_host_innerip"],
            "host_name": i["host"]["bk_host_name"],
            "os_name": i["host"]["bk_os_name"],
            "cloud_name": i["host"]["bk_cloud_id"][0]["bk_inst_name"],
            "cloud_id": i["host"]["bk_cloud_id"][0]["bk_inst_id"],
            "biz_id": filter_obj['biz_id'],
        }
        return_data.append(one_obj)
    return render_json({"result": True, "data": return_data})
Beispiel #10
0
def search_host(request):
    client = get_client_by_request(request)
    param = json.loads(request.body)
    if param.get('ip'):
        param['ip'] = param['ip'].split('\n')

    result = CcApiAdapter.search_host(client, **param)
    monitor_list = MonitorHost.objects.all()
    result_list = []
    if result['result']:
        for host in result['data']['info']:
            result_list.append({
                'ip':
                host['host']['bk_host_innerip'],
                'os_name':
                host['host']['bk_os_name'],
                'host_name':
                host['host']['bk_host_name'],
                'bk_cloud_id':
                host['host']['bk_cloud_id'][0]['id'],
                'bk_cloud_name':
                host['host']['bk_cloud_id'][0]['bk_inst_name'],
                'bk_biz_id':
                host['biz'][0]['bk_biz_id'],
                'is_monitor':
                host['host']['bk_host_innerip']
                in [item.ip for item in monitor_list]
            })

    return my_render_json(result_list)
Beispiel #11
0
def search_sys_data(request):
    client = get_client_by_request(request)
    param = json.loads(request.body)
    script_content = '''MEMORY=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')
DISK=$(df -h | awk '$NF=="/"{printf "%s", $5}')
CPU=$(top -bn1 | grep load | awk '{printf "%.2f%%", $(NF-2)}')
DATE=$(date "+%Y-%m-%d %H:%M:%S")
echo -e "$DATE|$MEMORY|$DISK|$CPU"'''
    is_success, log_dict = execute_script_and_get_log(client,
                                                      param['bk_biz_id'],
                                                      param['ip_list'],
                                                      script_content)
    if is_success:
        log_info = {}
        for log in log_dict.values():
            log_info = log

        metrics = log_info['log_content'].split('|')
        return my_render_json({
            'mem': metrics[1][:-1],
            'disk': metrics[2][:-1],
            'cpu': metrics[3][:-1],
        })

    else:
        return render_json({'reuslt': False, 'message': '查询失败'})
Beispiel #12
0
def search_host(request):
    # 根据集群查询主机
    set_id = int(request.GET["set"].split(":")[0])
    # client = get_client_by_user('admin')
    client = get_client_by_request(request)
    kwargs = {
        "condition": [{
            "bk_obj_id":
            "set",
            "fields": [],
            "condition": [{
                "field": "bk_set_id",
                "operator": "$eq",
                "value": set_id
            }]
        }]
    }
    host_result = client.cc.search_host(**kwargs)
    host_list = [{
        "id": biz["host"]["bk_host_id"],
        "innerip": biz["host"]["bk_host_innerip"]
    } for biz in host_result["data"]["info"]]
    # for biz in host_result["data"]["info"]:
    #     host_list.append({"id": biz["host"]["bk_host_id"], "innerip": biz["host"]["bk_host_innerip"]})

    return JsonResponse({"result": True, "data": host_list})
Beispiel #13
0
def add_host(request):
    params = json.loads(request.body)
    innerip = params["innerip"]
    business = params["biz"]
    if HostInfo.objects.filter(ip=innerip).exists():
        return JsonResponse({
            "result": False,
            "data": "请勿重复添加".format(innerip)
        })
    # client = get_client_by_user('admin')
    client = get_client_by_request(request)
    params = {
        "ip": {
            "data": [innerip],
            "exact": 1,
            "flag": "bk_host_innerip|bk_host_outerip"
        },
    }
    host_result = client.cc.search_host(**params)
    host_info = host_result["data"]["info"][0]["host"]

    HostInfo.objects.create(
        ip=host_info["bk_host_innerip"],
        name=host_info["bk_host_name"],
        business=business,
        cloud_area=host_info["bk_cloud_id"][0]["bk_inst_name"],
        os=host_info["bk_os_name"])
    return JsonResponse({"result": True, "data": host_result})
Beispiel #14
0
def search_server_list(request):
    filter_obj = eval(request.body)
    bk_biz_id = request.GET["bk_biz_id"]
    client = get_client_by_request(request)
    if filter_obj["bk_obj_id"] not in ['biz', 'module', 'set']:
        filter_obj["bk_obj_id"] = 'object'
        condition = [{
            "field": "bk_inst_id",
            "operator": "$eq",
            "value": int(filter_obj["value"])
        }]
    else:
        condition = [{
            "field": "bk_%s_id" % filter_obj["bk_obj_id"],
            "operator": "$eq",
            "value": int(filter_obj["value"])
        }]
    kwargs = {
        'bk_biz_id':
        bk_biz_id,
        "condition": [{
            "bk_obj_id": filter_obj["bk_obj_id"],
            "fields": [],
            "condition": condition
        }, {
            "bk_obj_id": "host",
            "fields": [],
            "condition": []
        }]
    }
    result = client.cc.search_host(kwargs)
    return render_json({
        "result": True,
        'data': [i['host'] for i in result["data"]["info"]]
    })
Beispiel #15
0
def get_host(request):
    params = json.loads(request.body)
    bk_host_innerip__in = params.get('bk_host_innerip__in')
    client = get_client_by_request(request)
    res = search_host_esb(client, request.user.username)
    result = []
    for item in res['data']:
        params = {
            'bk_host_innerip': item['host']['bk_host_innerip'],
            'bk_host_name': item['host']['bk_host_name'],
            'bk_os_name': item['host']['bk_os_name'],
            'bk_inst_name': item['host']['bk_cloud_id'][0]['bk_inst_name'],
            'bk_cloud_id': item['host']['bk_cloud_id'][0]['id'],
            'bk_biz_id': item['biz'][0]['bk_biz_id'],
            'bk_biz_name': item['biz'][0]['bk_biz_name'],
            'last_user': request.user.username
        }
        host_info, is_exist = HostInfo.objects.update_or_create(**params)
        if is_exist:
            host_info.last_user = request.user.username
            host_info.save()

    if bk_host_innerip__in:
        bk_host_innerip__in = bk_host_innerip__in.split(',')
        host_info = HostInfo.objects.filter(bk_host_innerip__in=bk_host_innerip__in)
    else:
        host_info = HostInfo.objects.all()
    for host in host_info:
        result.append(model_to_dict(host))

    return render_json({'data': result})
def job_fast_execute_script(request):
    """
    快速执行脚本
    :param request:
    :return:
    """
    bk_cloud_id = 0
    ip = "192.168.148.103"
    biz_id = 2
    ip_list = [{
        "bk_cloud_id": bk_cloud_id,
        "ip": ip
    }]
    client = get_client_by_request(request)
    content = """
        #!/bin/bash
        cat /proc/loadavg
    """  # 脚本内容
    params = {
        'bk_username': '******',
        'bk_biz_id': int(biz_id),
        'script_content': base64.b64encode(content),
        'account': "root",
        'bk_callback_url': "root",
        'script_type': 1,
        'ip_list': ip_list,
    }  # 参数
    resp = client.job.fast_execute_script(**params)

    if resp.get('code') == 0:
        return resp["data"]
    def search_biz_set_module(cls, request):
        """
            根据业务id 集群id 获取模块信息
            参数:biz_id 业务ID
        """
        biz_id = request.GET.get('biz_id', 2)
        set_id = request.GET.get('set_id', 4)
        # biz_id = 2  # 测试默认
        kwargs = {'bk_biz_id': biz_id}
        client = get_client_by_request(request)
        info = client.cc.search_biz_inst_topo(kwargs)

        result_list = []
        for topo in info['data']:
            for op in topo['child']:
                if op.get('bk_inst_id', '') and int(
                        op['bk_inst_id']) == set_id:
                    if len(op['child']):
                        for mo in op['child']:
                            result_list.append({
                                'name': mo['bk_inst_name'],
                                'id': mo['bk_inst_id'],
                                'bk_obj_id': mo['bk_obj_id']
                            })

        return JsonResponse({"data": result_list})
Beispiel #18
0
    def get_job_instance_ip_log(cls, request):
        """根据作业实例 ID 查询作业执行日志 根据ip查询作业执行日志"""
        biz_id = request.GET.get('biz_id', 2)
        # 所有需要的参数目前都是默认的,后续会整理  step_instance_id 通过get_job_instance_status 获取
        job_instance_id = request.GET.get('job_instance_id',
                                          20000000294)  # 作业实例ID
        ip_list = ['172.27.1.63', '172.27.0.96']
        step_instance_id = ['20000000295', '20000000296']
        client = get_client_by_request(request)
        for ip in ip_list:
            for step in step_instance_id:
                print(ip, '----------', step)
                kwargs = {
                    'bk_biz_id': biz_id,
                    'job_instance_id': job_instance_id,  # 作业实例ID
                    'step_instance_id': int(step),  # 步骤实例ID
                    'bk_cloud_id': 0,
                    'ip': ip
                }

                info = client.job.get_job_instance_ip_log(kwargs)
                print(info['data']['log_content'])
        # if info['result']:
        #     return JsonResponse(info)
        # else:
        #     return JsonResponse(info)
        return JsonResponse({'data': 'success'})
 def search_topo_tree(cls, request):
     """根据业务 id 查询集群模板"""
     bk_biz_id = request.GET.get('bk_biz_id', 2)
     client = get_client_by_request(request)
     kwargs = {"bk_biz_id": bk_biz_id}
     info = client.cc.search_topo_tree(kwargs)  # 接口文档有误,接口已弃用,但是文档中未删除
     return JsonResponse({"data": info['data']})
Beispiel #20
0
def init_host(request, total=1, start=0):
    client = get_client_by_request(request)
    kwargs = {
        "condition": [{
            "bk_obj_id": "biz",
            "fields": ['bk_biz_id'],
            "condition": []
        }, {
            "bk_obj_id":
            "host",
            "fields": [],
            "condition": [{
                "field": "bk_host_innerip",
                "operator": "$eq",
                "value": '172.16.150.35'
            }]
        }]
    }
    result = client.cc.search_host(kwargs)
    count = result.get("data").get("count", 0) if result.get("data") else None
    print result
    # for key in result.get("data").get("info"):
    #     bk_host_innerip = key.get('host').get('bk_host_innerip')
    #     host = UHost.objects.filter(ip=bk_host_innerip)
    #     if host:
    #         continue
    #     UHost.objects.create(ip=key.get('host').get('bk_host_innerip'),
    #                          name=key.get('host').get('bk_host_name'),
    #                          op_system=key.get('host').get('bk_os_name'),
    #                          area=key.get('host').get('bk_cloud_id')[0].get('bk_inst_name'),
    #                          business=key.get('biz')[0].get("bk_biz_name"))
    # if count == total:
    #     init_business(request=request, total=total, start=start + count)
    return HttpResponse(u"<p>数据添加成功1!</p>")
Beispiel #21
0
def get_ip_by_bizid(request):
    """
    获取业务下IP
    """
    biz_id = int(request.GET.get('biz_id'))
    client = get_client_by_request(request)
    kwargs = {
        'bk_biz_id':
        biz_id,
        'condition': [{
            'bk_obj_id':
            'biz',
            'fields': ['bk_biz_id'],
            'condition': [{
                'field': 'bk_biz_id',
                'operator': '$eq',
                'value': biz_id
            }]
        }]
    }
    resp = client.cc.search_host(**kwargs)

    ip_list = []
    if resp.get('result'):
        data = resp.get('data', {}).get('info', {})
        for _d in data:
            _hostinfo = _d.get('host', {})
            if _hostinfo.get('bk_host_innerip') not in ip_list:
                ip_list.append(_hostinfo.get('bk_host_innerip'))

    ip_all = [{'ip': _ip} for _ip in ip_list]
    result = {'result': resp.get('result'), 'data': ip_all}
    return render_json(result)
Beispiel #22
0
def execute_job(request):
    data = json.loads(request.body)
    client = get_client_by_request(request)
    res = execute_job_esb(client, request.user.username, data)
    ip_array = []
    if res['data']:
        for ip in data['ip_list']:
            ip_array.append(ip['ip'])
        create_data = {
            'bk_biz_id':
            data['bk_biz_id'],
            'bk_biz_name':
            res['data']['job_instance_name'],
            'user_name':
            request.user.username,
            'ip':
            ','.join(ip_array),
            'job_id':
            1,
            'job_instance_id':
            res['data']['job_instance_id'],
            'operate_time':
            time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),
            'job_status':
            2,
            'job_log':
            ''
        }
        JobHistory.objects.create(**create_data)
    return render_json(res)
Beispiel #23
0
def get_task_list(request):
    """
    获取所有任务类型
    :return:
    """
    myclient = get_client_by_request(request)
    myclient.set_bk_api_ver('v2')
    kwargs = {
        "fields": ["bk_biz_id", "bk_biz_name"],
    }
    biz_list = []
    myresult = myclient.cc.search_business(kwargs)
    if myresult.get('result'):
        biz_list = myresult.get('data').get('info')
    else:
        logger.info(u"请求业务列表失败:%s" % myresult.get('message'))
        biz_list = []

    all_tasks = TaskInfo.objects.all()
    task_type_list = []

    for task in all_tasks:
        task_type_list.append({'id': task.id, 'type': task.task_type})
    return render_mako_context(request, '/home_application/index1.html', {
        'result': True,
        'task_type_list': task_type_list,
        'biz_list': biz_list
    })
Beispiel #24
0
def tmp_get_set(request):
    try:
        bk_biz_id = json.loads(request.body)["bk_biz_id"]
        client = get_client_by_request(request)
        kwargs = {
            'bk_biz_id': bk_biz_id,
            'condition': {},
            'fields': ["bk_set_id", "bk_set_name"],
            'page': {
                'limit': 20,
                'sort': 'bk_set_name',
                'start': 0
            }
        }
        res = client.cc.search_set(kwargs)
        if not res["result"]:
            return render_json({"result": False, "data": res["data"]})
        else:
            info = res["data"]["info"]
            result = [{
                "id": i["bk_set_id"],
                "text": i["bk_set_name"]
            } for i in info]
            return render_json({"result": True, "data": result})
    except Exception, e:
        return render_json({"result": False, "message": str(e)})
Beispiel #25
0
def nodeman_host_import(request):
    ip = '10.0.0.4'
    client = get_client_by_request(request)
    kwargs = {
        "bk_biz_id":
        2,
        "creator":
        "admin",
        "hosts": [{
            "inner_ips": ip,
            "outer_ip": ip,
            "os_type": "LINUX",
            "has_cygwin": False,
            "port": 22,
            "account": "root",
            "auth_type": "PASSWORD",
            "password": '******',
            "key": " "
        }],
        "bk_cloud_id":
        "adf",
        "node_type":
        "PAGENT",
        "op_type":
        "INSTALL",
    }
    resp = client.nodeman.create_task(**kwargs)
Beispiel #26
0
def get_inner_host_info(request):
    """

    :return: [{"ip": 10.10.0.10, "os_type": "linux", "hostname": "default"}...]
    """
    # 获取内部数据库中的主机信息ip, os_type, hostname
    logger.info(u"获取内部数据库中的主机信息ip, os_type, hostname")
    client = get_client_by_request(request)
    kwargs = {
        "app_code": APP_ID,
        "app_secret": APP_TOKEN,
        "app_id": 1,
        "bk_token": request.COOKIES['bk_token']
    }
    result = client.bhcp.get_ip(kwargs)
    data = result['data']
    logger.debug(data)
    response_data = []
    for item in data:
        response_data.append({
            "ip": item['ip'],
            "os_type": item['os_type'],
            "hostname": item['hostname']
        })
    logger.debug(response_data)
    return response_data
Beispiel #27
0
def execute_script_by_id(request,
                         bk_biz_id,
                         script_id,
                         ip_list,
                         script_param=''):
    """
    快速执行作业平台给定ID的脚本
    :param script_param: string 脚本参数(非必填)
    :param ip_list: array 执行脚本的服务器列表,格式为:[{"bk_cloud_id": x, "ip": x.x.x.x}...]
    :param script_id: int 要执行的作业平台上的脚本的ID
    :param bk_biz_id: int 执行脚本的服务器所属业务ID
    :param request: http请求
    :return: 执行成功时返回脚本执行结果。失败时抛出一个异常。
    """
    client = get_client_by_request(request)
    params = {
        "bk_biz_id": bk_biz_id,
        "script_id": script_id,
        "script_param": base64.b64encode(script_param),
        "account": "root",
        "ip_list": ip_list,
        "script_timeout": 1000,
    }
    res = client.job.fast_execute_script(params)
    if res['result']:
        # 默认返回脚本执行结果,若获取出错可将下行代码改成 return res['data']['job_instance_id']来返回执行ID后再手动查询执行结果。
        return get_job_instance_log(request, bk_biz_id,
                                    res['data']['job_instance_id'])
    else:
        raise Exception(u'执行脚本失败: {}'.format(res['message']))
Beispiel #28
0
def queryHost(request):
    """
    首页
    """
    #ngTask.delay(4,4)
    allUser = NgUser.objects.all()

    # 默认从django settings中获取APP认证信息:应用ID和应用TOKEN
    # 默认从django request中获取用户登录态bk_token
    client = get_client_by_request(request)
    # 组件参数
    kwargs = {'ApplicationID': 3}
    result = client.opsdemo.listHost(kwargs)

    pass
    print 'host 列表'
    appId = {'app_id': 3}

    hosts = client.cc.get_app_host_list(appId)
    print hosts

    pass
    print 'task 列表'
    tasks = client.job.get_task(appId)
    print tasks

    print result

    return render_mako_context(request, '/home_application/query_host.html', {
        "hosts": hosts,
        "tasks": tasks
    })
Beispiel #29
0
def execute_job(request):
    try:
        filter_obj = json.loads(request.body)
        app_id = filter_obj["app_id"]["app_id"]
        server_list = filter_obj["data"]
        ip_list = []
        for i in server_list:
            ip_list.append({
                "bk_cloud_id": i["cloud_id"],
                "ip": i["ip_address"]
            })
            app_name = i["app_name"]
        client = get_client_by_request(request)
        # to_execute.delay(filter_obj, app_id, server_list, ip_list, request, client, app_name)
        # result = get_job_detail(client, request.user.username, app_id)
        # if result["result"]:
        #     job_info = result["data"]
        #     res = cc_execute_job(client, job_info, request.user.username, app_id, ip_list, app_name)
        #     if res:
        #         return render_json({"result": True})
        #     else:
        #         return render_json({"result": False})
        return render_json({"result": True})
    except Exception, e:
        print e
def job_fast_push_file(request):
    client = get_client_by_request(request)
    params = {
        "bk_biz_id": 2,  # 业务ID
        "account": "root",  # 执行帐号名/别名
        "file_target_path": "/tmp",  # 分发文件的目标路径
        "file_source": [
            {
                "files": [
                    "/root/test_push_file.txt"  # 源目标主机的源文件路径
                ],
                "account": "root",
                "ip_list": [
                    {
                        "bk_cloud_id": 0,
                        "ip": "192.168.148.103"  # 源目标主机
                    },
                ],
                # "custom_query_id": [
                #     "3"
                # ]
            }
        ],
        "ip_list": [
            {
                "bk_cloud_id": 0,
                "ip": "192.168.148.104"  # 目标主机
            },
        ],
    }
    res = client.job.fast_push_file(**params)

    if res.get('code') == 0:
        return True