Esempio n. 1
0
def highchart_api(request):

    pro_info = get_pro_info(request)

    areas = area_type.objects.values("area_name")
    area_list = []
    for i in areas:
        area_name = i["area_name"]
        area_list.append(area_name)

    data = []

    stack = 0
    for pro_name in pro_info:
        if stack == 0:
            stack_value = 'male'
            stack = 1
        else:
            stack_value = 'female'
            stack = 0
        pro_dict = {}
        area_hosts_count = []
        for aname in area_list:
            anum = host.objects.filter(project__name=pro_name,
                                       area__area_name=aname).count()
            area_hosts_count.append(anum)
        name = pro_name.name
        pro_dict['name'] = name
        pro_dict['stack'] = stack_value
        pro_dict['data'] = area_hosts_count
        data.append(pro_dict)

    return HttpResponse(json.dumps(data), content_type='application/json')
Esempio n. 2
0
def highchart_pie(request):

    pro_info = get_pro_info(request)
    data = []
    data_dic = {}
    data_dic["name"] = "Brands"
    data_list = []
    Denominator = pro_info.count()
    for pro_name in pro_info:
        pro_dic = {}
        if pro_name.name == "基础业务":
            pro_dic["sliced"] = bool('true'),
            pro_dic["selected"] = bool('true'),

        pro_dic['name'] = pro_name.name

        y_value = host.objects.filter(
            project__name=pro_name.name).count() / float(Denominator)

        pro_dic['y'] = y_value

        data_list.append(pro_dic)

    data_dic["data"] = data_list
    data.append(data_dic)

    return HttpResponse(json.dumps(data), content_type='application/json')
Esempio n. 3
0
def sshkey_list(request):
    header_title, nav, tip = "SSH密钥列表", "主机权限管理", "SSH密钥列表"
    af = KeyManagerForm()

    if request.method == 'POST':
        action = request.POST.get("action")
    else:
        action = request.GET.get("action")

    if action == "delete":
        key_id = request.GET.get("id")
        del_key = KeyManager.objects.filter(id=key_id)
        del_key.delete()

    elif action == "add":
        if request.method == 'POST':
            af_post = KeyManagerForm(request.POST)
            name = request.POST.get('name', '')
            try:
                if KeyManager.objects.filter(name=name):
                    error = u'该密钥 %s 已存在!' % name

            except Exception:
                pass

            else:
                if af_post.is_valid():
                    af_save = af_post.save(commit=False)
                    af_save.save()
                    af_post.save_m2m()
                    key_private = KeyManager.objects.get(name=name).private_key
                    write_ssh_key(key_private, name)
                else:
                    msg = "密钥 %s 添加失败" % name
    pro_info = cmdb_api.get_pro_info(request)
    pro_list = []
    for pro in pro_info:
        pro_list.append(pro.mini_name)
    sshkey_info = KeyManager.objects.filter(project__mini_name__in=pro_list)
    contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(
        sshkey_info, request)
    return render_to_response('hosts/sshkey_list.html',
                              locals(),
                              context_instance=RequestContext(request))
Esempio n. 4
0
def exec_cmds(request):
    header_title, nav, tip = "批量命令", "批量任务", "批量命令"
    project = request.GET.get("project")
    log = request.GET.get("log")
    error = request.GET.get("error")
    zone = project

    pro_info = cmdb_api.get_pro_info(request)

    if len(pro_info) == 0:
        log = "您的账号没有任何项目权限"

    if project is None:
        project = Project.objects.all()[0].mini_name

    else:
        host_info = host.objects.filter(project__mini_name=project, recover=0)
    return render_to_response('multitask/exec_cmds.html',
                              locals(),
                              context_instance=RequestContext(request))
Esempio n. 5
0
def exec_script_hosts(request):
    header_title, nav, tip = "选择服务器", "批量任务", "脚本分发"
    project = request.GET.get("project")
    area_name = request.GET.get("area")

    project_info = cmdb_api.get_pro_info(request)

    if len(project_info) == 0:
        log = "您的账号没有任何项目权限"
    zone = project

    if project is None:
        project = Project.objects.all()[0].mini_name

    else:
        menu = host.objects.filter(project__mini_name=project,
                                   area__mini_name=area_name,
                                   recover=0).order_by("p_ip")

    if area_name is None:
        area_name = area_type.objects.all()[0].mini_name

    zone = area_name

    pro_area_info = {}
    for p in project_info:
        area_list = []
        area_obj = host.objects.filter(
            project__mini_name=p.mini_name).values("area").distinct()
        for z in area_obj:
            area_mini_name = area_type.objects.get(id=z["area"]).mini_name
            area_list.append(area_mini_name)
        pro_area_info.setdefault(p.mini_name, area_list)

    return render_to_response('multitask/exec_script_hosts.html',
                              locals(),
                              context_instance=RequestContext(request))