def sreg_convert(system, messages):
    bundles = []
    for name in generate_possible_names(system.hostname):
        bundles += generate_sreg_bundles(system, name)

    results = []
    for bundle in bundles:
        res = _combine(bundle, transaction_managed=True, use_reversion=False)
        messages.append("\t(Converted A/PTR to create '{0}')".format(res))
        results.append(res)
    return results
Beispiel #2
0
def sreg_convert(system, messages):
    bundles = []
    for name in generate_possible_names(system.hostname):
        bundles += generate_sreg_bundles(system, name)

    results = []
    for bundle in bundles:
        res = _combine(bundle, transaction_managed=True, use_reversion=False)
        messages.append("\t(Converted A/PTR to create '{0}')".format(res))
        results.append(res)
    return results
Beispiel #3
0
def combine_status_list(request):
    """
    This view is temporary. It can be used to convert a system using KV objects
    for dhcp into the new Sreg and HW scheme.
    """
    def get(thing, default):
        if thing in request.POST:
            return request.POST.get(thing)
        return request.GET.get(thing, default)

    qd = request.POST or request.GET
    if qd:
        convert_everything = get('convert-everything', False)
        search = get('search', '')
        records, error = search_type(search, 'SYS')
        if not search or error:
            records = []
            total = 0
        else:
            try:
                total = records.count()
                records = records
            except MySQLdb.OperationalError, e:
                if "Got error " in str(e) and " from regexp" in str(e):
                    # This is nasty. If the user is using an invalid regex
                    # patter, the db might shit a brick
                    total = 0
                    records = []
                else:
                    raise

        bundles = []
        for system in records:
            for name in generate_possible_names(system.hostname):
                bundles += generate_sreg_bundles(system, name)

        if convert_everything:
            combine_multiple(bundles, rollback=False)
            bundles = []
        else:
            combine_multiple(bundles, rollback=True)

        return render(request, 'static_reg/combine_status_list.html', {
            'bundles': bundles,
            'search': search,
            'total': total
        })
Beispiel #4
0
def combine_status_list(request):
    """
    This view is temporary. It can be used to convert a system using KV objects
    for dhcp into the new Sreg and HW scheme.
    """
    def get(thing, default):
        if thing in request.POST:
            return request.POST.get(thing)
        return request.GET.get(thing, default)

    qd = request.POST or request.GET
    if qd:
        convert_everything = get('convert-everything', False)
        search = get('search', '')
        records, error = search_type(search, 'SYS')
        if not search or error:
            records = []
            total = 0
        else:
            try:
                total = records.count()
                records = records
            except MySQLdb.OperationalError, e:
                if "Got error " in str(e) and " from regexp" in str(e):
                    # This is nasty. If the user is using an invalid regex
                    # patter, the db might shit a brick
                    total = 0
                    records = []
                else:
                    raise

        bundles = []
        for system in records:
            for name in generate_possible_names(system.hostname):
                bundles += generate_sreg_bundles(system, name)

        if convert_everything:
            combine_multiple(bundles, rollback=False)
            bundles = []
        else:
            combine_multiple(bundles, rollback=True)

        return render(request, 'static_reg/combine_status_list.html', {
            'bundles': bundles,
            'search': search,
            'total': total
        })
Beispiel #5
0
def ajax_combine_sreg(request):
    if not request.POST:
        return HttpResponse(
            json.dumps({
                'success': False,
                'errors': 'Missing object pks'
            }))

    a_pk = request.POST.get('a_pk', None)
    ptr_pk = request.POST.get('ptr_pk', None)
    system_pk = request.POST.get('system_pk', None)
    name = request.POST.get('name', None)

    if not (a_pk and ptr_pk and system_pk and name):
        return HttpResponse(
            json.dumps({
                'success': False,
                'errors': 'Missing object pks'
            }))

    a_pk, ptr_pk, system_pk = int(a_pk), int(ptr_pk), int(system_pk)

    system = get_object_or_404(System, pk=system_pk)

    bundles = generate_sreg_bundles(system, name)

    bundle = None
    for a_bundle in bundles:
        if (a_bundle['a'].pk == a_pk and a_bundle['ptr'].pk == ptr_pk
                and a_bundle['system'].pk == system_pk
                and a_bundle['fqdn'] == name):
            bundle = a_bundle
            break

    assert bundle is not None

    combine(bundle)

    return HttpResponse(
        json.dumps({
            'success': not bundle['errors'],
            'redirect_url': system.get_absolute_url(),
            'errors': bundle.get('errors', '')
        }))
Beispiel #6
0
def ajax_combine_sreg(request):
    if not request.POST:
        return HttpResponse(json.dumps({
            'success': False,
            'errors': 'Missing object pks'
        }))

    a_pk = request.POST.get('a_pk', None)
    ptr_pk = request.POST.get('ptr_pk', None)
    system_pk = request.POST.get('system_pk', None)
    name = request.POST.get('name', None)

    if not (a_pk and ptr_pk and system_pk and name):
        return HttpResponse(json.dumps({
            'success': False,
            'errors': 'Missing object pks'
        }))

    a_pk, ptr_pk, system_pk = int(a_pk), int(ptr_pk), int(system_pk)

    system = get_object_or_404(System, pk=system_pk)

    bundles = generate_sreg_bundles(system, name)

    bundle = None
    for a_bundle in bundles:
        if (a_bundle['a'].pk == a_pk and a_bundle['ptr'].pk == ptr_pk and
                a_bundle['system'].pk == system_pk and
                a_bundle['fqdn'] == name):
            bundle = a_bundle
            break

    assert bundle is not None

    combine(bundle)

    return HttpResponse(json.dumps({
        'success': not bundle['errors'],
        'redirect_url': system.get_absolute_url(),
        'errors': bundle.get('errors', '')
    }))