Esempio n. 1
0
def host_expected_to_be_down(management_profile):
    box = Netbox(ip='10.254.254.254', sysname='downhost.example.org',
                 organization_id='myorg', room_id='myroom', category_id='SRV')
    box.save()
    NetboxProfile(netbox=box, profile=management_profile).save()
    yield box
    print("teardown test device")
    box.delete()
Esempio n. 2
0
 def _get_management_profiles(netbox, profile_names):
     profiles = profile_names.split('|')
     profiles = [
         get_object_or_fail(ManagementProfile, name=name)
         for name in profiles if name.strip()
     ]
     return [
         NetboxProfile(netbox=netbox, profile=profile)
         for profile in profiles
     ]
Esempio n. 3
0
def localhost(management_profile):
    from nav.models.manage import Netbox, NetboxProfile
    box = Netbox(ip='127.0.0.1',
                 sysname='localhost.example.org',
                 organization_id='myorg',
                 room_id='myroom',
                 category_id='SRV')
    box.save()
    NetboxProfile(netbox=box, profile=management_profile).save()
    yield box
    print("teardown test device")
    box.delete()
Esempio n. 4
0
def netbox(db, management_profile):
    box = Netbox(ip='10.254.254.254', sysname='example-sw.example.org',
                 organization_id='myorg', room_id='myroom', category_id='SW')
    box.save()
    NetboxProfile(netbox=box, profile=management_profile).save()

    device = Device(serial="1234test")
    device.save()
    module = Module(device=device, netbox=box, name='Module 1', model='')
    module.save()

    interface = Interface(netbox=box, module=module, ifname='1',
                          ifdescr='Port 1')
    interface.save()

    return box
Esempio n. 5
0
def test_get_snmp_config_should_pick_highest_available_snmp_version(
    db,
    localhost,
    wanted_profile,
    faulty_profile,
    snmpv1_string_profile,
    snmpv1_integer_profile,
    null_profile,
):
    for profile in (
            faulty_profile,
            snmpv1_integer_profile,
            wanted_profile,
            snmpv1_string_profile,
            null_profile,
    ):
        profile.save()
        NetboxProfile(netbox=localhost, profile=profile).save()

    assert (localhost._get_snmp_config(
        variable="community") == wanted_profile.configuration["community"])
Esempio n. 6
0
def netbox_do_save(form):
    """Save netbox.

    Netboxgroups needs to be set manually because of database structure, thus we
    do a commit=False save first.
    """

    netbox = form.save(commit=False)  # Prevents saving m2m relationships
    netbox.save()

    # Save the function field
    function = form.cleaned_data['function']
    if function:
        try:
            func = NetboxInfo.objects.get(netbox=netbox, variable='function')
        except NetboxInfo.DoesNotExist:
            func = NetboxInfo(netbox=netbox,
                              variable='function',
                              value=function)
        else:
            func.value = function
        func.save()

    # Save the groups
    netboxgroups = form.cleaned_data['groups']
    NetboxCategory.objects.filter(netbox=netbox).delete()
    for netboxgroup in netboxgroups:
        NetboxCategory.objects.create(netbox=netbox, category=netboxgroup)

    # Update the list of management profiles
    current_profiles = set(form.cleaned_data['profiles'])
    old_profiles = set(netbox.profiles.all())
    to_add = current_profiles.difference(old_profiles)
    to_remove = old_profiles.difference(current_profiles)
    for profile in to_remove:
        NetboxProfile.objects.get(netbox=netbox, profile=profile).delete()
    for profile in to_add:
        NetboxProfile(netbox=netbox, profile=profile).save()

    return netbox