def _get_netbox_from_row(row): netbox = Netbox(ip=row['ip'], read_only=row['ro'], read_write=row['rw'], snmp_version=1) netbox.room = get_object_or_fail(Room, id=row['roomid']) netbox.organization = get_object_or_fail(Organization, id=row['orgid']) netbox.category = get_object_or_fail(Category, id=row['catid']) netbox.sysname = netbox.ip return netbox
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_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 setUp(self): """Test setup""" netbox1 = Netbox() netbox1.get_availability = Mock( return_value = {'availability': {'day': None, 'month': 100.0, 'week': 100.0}}) netbox2 = Netbox() netbox2.get_availability = Mock( return_value = {'availability': {'day': None, 'month': 100.0, 'week': None}}) self.netboxes = [netbox1, netbox2]
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
def update(self, request, *args, **kwargs): viewid = kwargs.pop('viewid') data = request.DATA.get('data', []) # nodes to be updated in the topology cache cache_updates = [] for d in data: defaults = { 'x': int(d['x']), 'y': int(d['y']), } obj, created = NetmapViewNodePosition.objects.get_or_create( viewid=NetmapView(pk=viewid), netbox=Netbox(pk=int(d['netbox'])), defaults=defaults) if not created: obj.x = defaults['x'] obj.y = defaults['y'] obj.save() cache_updates.append({ "id": str(obj.netbox.id), "x": defaults["x"], "y": defaults["y"], "new_node": created }) # Invalidate cached position if cache_exists("topology", viewid, "layer 2"): update_cached_node_positions(viewid, "layer 2", cache_updates) if cache_exists("topology", viewid, "layer 3"): update_cached_node_positions(viewid, "layer 3", cache_updates) return Response({"status": "OK"})
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_factory(self, sysname, interface=None): netbox = Netbox() netbox.id = self._next_id() netbox.sysname = sysname netbox.interface = interface netbox.category = self.category_gw netbox.room = self.room netbox.ip = '::{0}'.format(self.model_id) return netbox
def _netbox_factory(self, sysname, interface=None): netbox = Netbox() netbox.id = self._next_id() netbox.sysname = sysname netbox.interface = interface netbox.category = self.category_gw netbox.room = self.room netbox.ip = '::{0}'.format(self.model_id) return netbox
def setUp(self): self.event = Event( source=Subsystem('someone'), netbox=Netbox(), device=Device(), subid="thing", event_type=EventType('boxState'), state=Event.STATE_START, time=datetime.datetime.now(), value=50, severity=80, )
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 _get_netbox_from_row(row): netbox = Netbox(ip=row['ip']) netbox.room = get_object_or_fail(Room, id=row['roomid']) netbox.organization = get_object_or_fail(Organization, id=row['orgid']) netbox.category = get_object_or_fail(Category, id=row['catid']) netbox.sysname = netbox.ip master = row.get('master') if master: if is_valid_ip(master, use_socket_lib=True): netbox.master = get_object_or_fail(Netbox, ip=master) else: netbox.master = get_object_or_fail(Netbox, sysname__startswith=master) return netbox
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 _get_netbox_from_row(row): netbox = Netbox(ip=row['ip'], read_only=row['ro'], read_write=row['rw'], snmp_version=1) netbox.room = get_object_or_fail(Room, id=row['roomid']) netbox.organization = get_object_or_fail(Organization, id=row['orgid']) netbox.category = get_object_or_fail(Category, id=row['catid']) netbox.sysname = netbox.ip 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 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 setUp(self): """Test setup""" netbox1 = Netbox() netbox1.get_availability = Mock(return_value={ 'availability': { 'day': None, 'month': 100.0, 'week': 100.0 } }) netbox2 = Netbox() netbox2.get_availability = Mock(return_value={ 'availability': { 'day': None, 'month': 100.0, 'week': None } }) self.netboxes = [netbox1, netbox2]