def _interface_factory(self, ifname, netbox): interface = Interface() interface.id = self._next_id() interface.ifname = ifname if netbox and isinstance(netbox, Netbox): interface.netbox = netbox elif netbox: interface.netbox = self._netbox_factory(netbox, interface) return interface
def _save_trunk_interface(interface: manage.Interface, native_vlan: int, trunk_vlans: Sequence[int]): """Updates the Interface entry in the database with trunk config""" interface.trunk = True interface.vlan = native_vlan allowedvlan, _ = manage.SwPortAllowedVlan.objects.get_or_create( interface=interface) allowedvlan.set_allowed_vlans(trunk_vlans) allowedvlan.save() interface.save()
def _save_access_interface(interface: manage.Interface, access_vlan: int): """Updates the Interface entry in the database with access config""" interface.trunk = False interface.vlan = access_vlan try: allowedvlans = interface.swportallowedvlan allowedvlans.save() except manage.SwPortAllowedVlan.DoesNotExist: pass interface.save()
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
def _save_interface_oper(interface: manage.Interface, ifoperstatus: int): master, unit = split_master_unit(interface.ifname) interface.ifoperstatus = ifoperstatus if unit: # this was a logical unit, also set the state of the master ifc master_interface = manage.Interface.objects.filter( netbox=interface.netbox, ifname=master) master_interface.update(ifoperstatus=ifoperstatus)
def test_non_existent_subid_reference_should_return_unknown_event_subject( self, event, ): event.event_type_id = 'linkState' event.subid = '42' with patch( "nav.models.manage.Interface.objects.get", side_effect=Interface.DoesNotExist(), ): assert isinstance(event.get_subject(), UnknownEventSubject)