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()
def netbox(): box = Netbox(ip='10.254.254.254', sysname='downhost.example.org', organization_id='myorg', room_id='myroom', category_id='SRV', snmp_version=2) box.save() yield box print("teardown test device") box.delete()
def localhost(): from nav.models.manage import Netbox box = Netbox(ip='127.0.0.1', sysname='localhost.example.org', organization_id='myorg', room_id='myroom', category_id='SRV', read_only='public', snmp_version=2) box.save() yield box print("teardown test device") box.delete()
def netbox_do_save(form, serial_form, group_form): """Save netbox""" clean_data = form.cleaned_data primary_key = clean_data.get('id') data = { 'ip': clean_data['ip'], 'sysname': clean_data['sysname'], 'room': clean_data['room'], 'category': clean_data['category'], 'organization': clean_data['organization'], 'read_only': clean_data['read_only'], 'read_write': clean_data['read_write'], 'snmp_version': clean_data['snmp_version'], 'up_to_date': False, } serial = serial_form.cleaned_data['serial'] if serial: device, _ = Device.objects.get_or_create(serial=serial) data['device'] = device elif not primary_key: device = Device.objects.create(serial=None) data['device'] = device if 'type' in clean_data and clean_data['type']: data['type'] = NetboxType.objects.get(pk=clean_data['type']) if primary_key: netbox = Netbox.objects.get(pk=primary_key) for key in data: setattr(netbox, key, data[key]) else: netbox = Netbox(**data) netbox.save() function = serial_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() if group_form: netboxgroups = group_form.cleaned_data['netboxgroups'] NetboxCategory.objects.filter(netbox=netbox).delete() for netboxgroup in netboxgroups: NetboxCategory.objects.create(netbox=netbox, category=netboxgroup) return netbox
def netbox(management_profile): box = Netbox(ip='10.254.254.254', sysname='downhost.example.org', organization_id='myorg', room_id='myroom', category_id='SRV') box.save() yield box print("teardown test device") box.delete()
def netbox_do_save(form, serial_form, group_form): """Save netbox""" clean_data = form.cleaned_data primary_key = clean_data.get('id') data = { 'ip': clean_data['ip'], 'sysname': clean_data['sysname'], 'room': clean_data['room'], 'category': clean_data['category'], 'organization': clean_data['organization'], 'read_only': clean_data['read_only'], 'read_write': clean_data['read_write'], 'snmp_version': clean_data['snmp_version'], 'up_to_date': False, } serial = serial_form.cleaned_data['serial'] if serial: device, _ = Device.objects.get_or_create(serial=serial) data['device'] = device elif not primary_key: device = Device.objects.create(serial=None) data['device'] = device if 'type' in clean_data and clean_data['type']: data['type'] = NetboxType.objects.get(pk=clean_data['type']) if primary_key: netbox = Netbox.objects.get(pk=primary_key) for key in data: setattr(netbox, key, data[key]) else: netbox = Netbox(**data) netbox.save() function = serial_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() if group_form: netboxgroups = group_form.cleaned_data['netboxgroups'] NetboxCategory.objects.filter(netbox=netbox).delete() for netboxgroup in netboxgroups: NetboxCategory.objects.create(netbox=netbox, category=netboxgroup) return netbox
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()
def host_going_down(): box = Netbox( ip="10.254.254.254", sysname="downhost.example.org", organization_id="myorg", room_id="myroom", category_id="SRV", ) box.save() yield box print("teardown test device") box.delete()
def netbox(db): box = Netbox(ip='10.254.254.254', sysname='example-sw.example.org', organization_id='myorg', room_id='myroom', category_id='SW', snmp_version=2, read_only='public') box.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
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