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