Exemplo n.º 1
0
def bulk_action_export(request):
    search = request.GET.get('q', '')
    if not search:
        return HttpResponse(dumps({'errors': 'what do you want?'}))
    q_map, errors = compile_to_q(search)
    if errors:
        return HttpResponse(dumps({'errors': errors}))

    try:  # We might have to catch shitty regular expressions
        bundles = System.get_bulk_action_list(q_map['SYS'])
    except OperationalError as why:
        return HttpResponse(dumps({'error_messages': str(why)}))

    pprint.pprint(bundles)
    return HttpResponse(dumps({'systems': bundles}))
Exemplo n.º 2
0
def bulk_action_export(request):
    search = request.GET.get('q', '')
    if not search:
        return HttpResponse(dumps({'errors': 'what do you want?'}))
    q_map, errors = compile_to_q(search)
    if errors:
        return HttpResponse(dumps({'errors': errors}))

    try:  # We might have to catch shitty regular expressions
        bundles = System.get_bulk_action_list(q_map['SYS'])
    except OperationalError as why:
        return HttpResponse(dumps({'error_messages': str(why)}))

    pprint.pprint(bundles)
    return HttpResponse(dumps({'systems': bundles}))
Exemplo n.º 3
0
def bulk_gather_vlan_pools(request):
    vlan_name = request.GET.get('vlan_name', None)
    vlan_number = request.GET.get('vlan_number', None)
    site_name = request.GET.get('site_name', None)
    ip_type = request.GET.get('ip_type', None)

    if not site_name:
        return HttpResponse(dumps({'errors': 'Site name was not provided'}))

    if not ip_type:
        return HttpResponse(dumps({'errors': 'IP type is required here.'}))

    if vlan_name and vlan_number:
        s = 'site=:{site_name} AND vlan=:{vlan_name},{vlan_number}'.format(
            site_name=site_name, vlan_name=vlan_name, vlan_number=vlan_number)
    elif vlan_name:
        s = 'site=:{site_name} AND vlan=:{vlan_name}'.format(
            site_name=site_name, vlan_name=vlan_name)
    elif vlan_number:
        s = 'site=:{site_name} AND vlan=:{vlan_number}'.format(
            site_name=site_name, vlan_number=vlan_number)
    else:
        return HttpResponse(
            dumps({'errors': 'Not enough vlan information was provided'}))

    q_map, errors = compile_to_q(s)

    if errors:
        return None, errors

    networks = Network.objects.filter(q_map['NET']).filter(ip_type=ip_type)
    if networks.count() > 1:
        return HttpResponse(
            dumps({
                'errors':
                "Using the search '{s}', too many networks were "
                "found. Please be more specific and specify a range.".format(
                    s=s)
            }))
    if not networks.count():
        return HttpResponse(
            dumps({
                'errors':
                "Using the search '{s}', no networks were "
                "found.".format(s=s)
            }))

    ranges = integrate_real_ranges(networks[0],
                                   calc_template_ranges(networks[0]))
    free_ranges = []
    for r in ranges:
        if r['rtype'] == 'special purpose':
            continue
        free_ranges += range_usage(r['start'], r['end'],
                                   ip_type)['free_ranges']

    return HttpResponse(dumps({'free_ranges': free_ranges}))
Exemplo n.º 4
0
def bulk_gather_vlan_pools(request):
    vlan_name = request.GET.get('vlan_name', None)
    vlan_number = request.GET.get('vlan_number', None)
    site_name = request.GET.get('site_name', None)
    ip_type = request.GET.get('ip_type', None)

    if not site_name:
        return HttpResponse(dumps({
            'errors': 'Site name was not provided'
        }))

    if not ip_type:
        return HttpResponse(dumps({
            'errors': 'IP type is required here.'
        }))

    if vlan_name and vlan_number:
        s = 'site=:{site_name} AND vlan=:{vlan_name},{vlan_number}'.format(
            site_name=site_name, vlan_name=vlan_name, vlan_number=vlan_number
        )
    elif vlan_name:
        s = 'site=:{site_name} AND vlan=:{vlan_name}'.format(
            site_name=site_name, vlan_name=vlan_name
        )
    elif vlan_number:
        s = 'site=:{site_name} AND vlan=:{vlan_number}'.format(
            site_name=site_name, vlan_number=vlan_number
        )
    else:
        return HttpResponse(dumps({
            'errors': 'Not enough vlan information was provided'
        }))

    q_map, errors = compile_to_q(s)

    if errors:
        return None, errors

    networks = Network.objects.filter(q_map['NET']).filter(ip_type=ip_type)
    if networks.count() > 1:
        return HttpResponse(dumps({
            'errors': "Using the search '{s}', too many networks were "
            "found. Please be more specific and specify a range.".format(s=s)
        }))
    if not networks.count():
        return HttpResponse(dumps({
            'errors': "Using the search '{s}', no networks were "
            "found.".format(s=s)
        }))

    ranges = integrate_real_ranges(
        networks[0], calc_template_ranges(networks[0])
    )
    free_ranges = []
    for r in ranges:
        if r['rtype'] == 'special purpose':
            continue
        free_ranges += range_usage(
            r['start'], r['end'], ip_type
        )['free_ranges']

    return HttpResponse(dumps({
        'free_ranges': free_ranges
    }))
Exemplo n.º 5
0
def bulk_action_import(request):
    raw_data = request.raw_post_data
    if not raw_data:
        return HttpResponse(dumps({'errors': 'what do you want?'}))
    systems, errors = bulk_import(raw_data)
    return HttpResponse(json.dumps(systems or errors))
Exemplo n.º 6
0
def bulk_action_import(request):
    raw_data = request.raw_post_data
    if not raw_data:
        return HttpResponse(dumps({'errors': 'what do you want?'}))
    systems, errors = bulk_import(raw_data)
    return HttpResponse(json.dumps(systems or errors))