예제 #1
0
파일: views.py 프로젝트: trestea/cmdb-1
def host_search(request):
    """ 条件搜索ajax """

    idcs = IDC.objects.filter()
    lines = Line.objects.all()
    server_type = Project.objects.all()
    services = Service.objects.all()
    brands = Server_System
    server_status = SERVER_STATUS

    lines = Line.objects.all()
    businesses = Project.objects.all()
    idc_name = request.GET.get('change_idc', '')
    business_name = request.GET.get('change_business', '')
    service_name = request.GET.get('change_service', '')
    brand_name = request.GET.get('change_brand', '')
    if brand_name:
        brand_name = brand_name
    status = request.GET.get('change_status', False)
    if status:
        status = int(status)
    else:
        status = ""

    type = request.GET.get('change_type', '')

    if not idc_name and not type and not status and not brand_name and business_name == 'all' \
            and service_name == 'all':
        select_number = 0
    else:
        select_number = 1

    keyword = request.GET.get('keyword', '')
    s_url = request.get_full_path()

    if business_name == 'all' and service_name != 'all':
        ser = Service.objects.get(name=service_name)
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    service=ser,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    elif service_name == 'all' and business_name != 'all':
        business = Project.objects.get(service_name=business_name)
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    business=business,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    elif business_name == 'all' and service_name == 'all':
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    else:
        ser = Service.objects.get(name=service_name)
        business = Project.objects.get(service_name=business_name)
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    business=business,
                                    service=ser,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    if keyword and select_number == 1:
        hosts = hosts.filter(
            Q(node_name__contains=keyword) | Q(idc__name__contains=keyword)
            | Q(eth1__contains=keyword) | Q(eth2__contains=keyword)
            | Q(internal_ip__contains=keyword) | Q(brand__contains=keyword)
            | Q(number__contains=keyword) | Q(editor__contains=keyword)
            | Q(business__service_name__contains=keyword)
            | Q(service__name__contains=keyword)
            | Q(Services_Code__contains=keyword)
            | Q(server_sn__contains=keyword) | Q(cpu__contains=keyword)
            | Q(memory__contains=keyword) | Q(hard_disk__contains=keyword))

    elif keyword:
        hosts = Host.objects.filter(
            Q(node_name__contains=keyword) | Q(idc__name__contains=keyword)
            | Q(eth1__contains=keyword) | Q(eth2__contains=keyword)
            | Q(internal_ip__contains=keyword) | Q(brand__contains=keyword)
            | Q(number__contains=keyword) | Q(editor__contains=keyword)
            | Q(business__service_name__contains=keyword)
            | Q(service__name__contains=keyword)
            | Q(Services_Code__contains=keyword)
            | Q(server_sn__contains=keyword) | Q(cpu__contains=keyword)
            | Q(memory__contains=keyword) | Q(hard_disk__contains=keyword))

    hosts = list(set(hosts))
    hosts_dic = {}
    hosts_lis = []
    for host in hosts:
        if host.eth1:
            hosts_dic[host.eth1] = host
            hosts_lis.append(host.eth1)
        elif host.eth2:
            hosts_dic[host.eth2] = host
            hosts_lis.append(host.eth2)
    sort_ip_list(hosts_lis)
    hosts = []
    for eth1 in hosts_lis:
        hosts.append(hosts_dic[eth1])

    search_status = request.GET.get("_search", False)
    search_output_name = request.GET.get("name", False)
    if search_status and search_output_name:
        if search_output_name == 'pdf':
            s = rpt(hosts)
            if s:
                data = "pdf"
                return render_to_response(
                    'assets/download.html',
                    locals(),
                    context_instance=RequestContext(request))

        if search_output_name == 'excel':
            s = excel_output(hosts)
            if s:
                data = "execl"
                return render_to_response(
                    'assets/download.html',
                    locals(),
                    context_instance=RequestContext(request))

    contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(
        hosts, request)

    if 'ajax' in request.get_full_path():
        s_url = s_url.replace('change_info_ajax', 'host_search')
        return my_render('assets/host_info_ajax.html', locals(), request)
    else:
        hosts = Host.objects.all()
        idcs = IDC.objects.filter()
        lines = Line.objects.all()
        server_type = Project.objects.all()
        services = Service.objects.all()
        brands = Server_System
        server_status = SERVER_STATUS
        server_list_count = hosts.count()
        physics = Host.objects.filter(vm__isnull=True).count()
        vms = Host.objects.filter(vm__isnull=False).count()
        search = 1
        return my_render('assets/host_list.html', locals(), request)
예제 #2
0
파일: views.py 프로젝트: voilet/cmdb
def host_search(request):
    """ 条件搜索ajax """

    idcs = IDC.objects.filter()
    lines = Line.objects.all()
    server_type = Project.objects.all()
    services = Service.objects.all()
    brands = Server_System
    server_status = SERVER_STATUS

    lines = Line.objects.all()
    businesses = Project.objects.all()
    idc_name = request.GET.get('change_idc', '')
    business_name = request.GET.get('change_business', '')
    service_name = request.GET.get('change_service', '')
    brand_name = request.GET.get('change_brand', '')
    if brand_name:
        brand_name = brand_name
    status = request.GET.get('change_status', False)
    if status:
        status = int(status)
    else:
        status = ""

    type = request.GET.get('change_type', '')

    if not idc_name and not type and not status and not brand_name and business_name == 'all' \
            and service_name == 'all':
        select_number = 0
    else:
        select_number = 1

    keyword = request.GET.get('keyword', '')
    s_url = request.get_full_path()

    if business_name == 'all' and service_name != 'all':
        ser = Service.objects.get(name=service_name)
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    service=ser,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    elif service_name == 'all' and business_name != 'all':
        business = Project.objects.get(service_name=business_name)
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    business=business,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    elif business_name == 'all' and service_name == 'all':
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    else:
        ser = Service.objects.get(name=service_name)
        business = Project.objects.get(service_name=business_name)
        hosts = Host.objects.filter(idc__name__contains=idc_name,
                                    business=business,
                                    service=ser,
                                    brand__contains=brand_name,
                                    status__contains=status,
                                    type__contains=type)

    if keyword and select_number == 1:
        hosts = hosts.filter(Q(node_name__contains=keyword) |
                             Q(idc__name__contains=keyword) |
                             Q(eth1__contains=keyword) |
                             Q(eth2__contains=keyword) |
                             Q(internal_ip__contains=keyword) |
                             Q(brand__contains=keyword) |
                             Q(number__contains=keyword) |
                             Q(editor__contains=keyword) |
                             Q(business__service_name__contains=keyword) |
                             Q(service__name__contains=keyword) |
                             Q(Services_Code__contains=keyword) |
                             Q(server_sn__contains=keyword) |
                             Q(cpu__contains=keyword) |
                             Q(memory__contains=keyword) |
                             Q(hard_disk__contains=keyword))

    elif keyword:
        hosts = Host.objects.filter(Q(node_name__contains=keyword) |
                                    Q(idc__name__contains=keyword) |
                                    Q(eth1__contains=keyword) |
                                    Q(eth2__contains=keyword) |
                                    Q(internal_ip__contains=keyword) |
                                    Q(brand__contains=keyword) |
                                    Q(number__contains=keyword) |
                                    Q(editor__contains=keyword) |
                                    Q(business__service_name__contains=keyword) |
                                    Q(service__name__contains=keyword) |
                                    Q(Services_Code__contains=keyword) |
                                    Q(server_sn__contains=keyword) |
                                    Q(cpu__contains=keyword) |
                                    Q(memory__contains=keyword) |
                                    Q(hard_disk__contains=keyword))

    hosts = list(set(hosts))
    hosts_dic = {}
    hosts_lis = []
    for host in hosts:
        if host.eth1:
            hosts_dic[host.eth1] = host
            hosts_lis.append(host.eth1)
        elif host.eth2:
            hosts_dic[host.eth2] = host
            hosts_lis.append(host.eth2)
    sort_ip_list(hosts_lis)
    hosts = []
    for eth1 in hosts_lis:
        hosts.append(hosts_dic[eth1])

    search_status = request.GET.get("_search", False)
    search_output_name = request.GET.get("name", False)
    if search_status and search_output_name:
        if search_output_name == 'pdf':
            s = rpt(hosts)
            if s:
                data = "pdf"
                return render_to_response('assets/download.html', locals(), context_instance=RequestContext(request))

        if search_output_name == 'excel':
            s = excel_output(hosts)
            if s:
                data = "execl"
                return render_to_response('assets/download.html', locals(), context_instance=RequestContext(request))

    contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(hosts, request)

    if 'ajax' in request.get_full_path():
        s_url = s_url.replace('change_info_ajax', 'host_search')
        return my_render('assets/host_info_ajax.html', locals(), request)
    else:
        hosts = Host.objects.all()
        idcs = IDC.objects.filter()
        lines = Line.objects.all()
        server_type = Project.objects.all()
        services = Service.objects.all()
        brands = Server_System
        server_status = SERVER_STATUS
        server_list_count = hosts.count()
        physics = Host.objects.filter(vm__isnull=True).count()
        vms = Host.objects.filter(vm__isnull=False).count()
        search = 1
        return my_render('assets/host_list.html', locals(), request)