Add LLDP auto cabling #41

Merged
Solvik merged 8 commits from feature/lldp into master 2019-08-26 11:05:42 +02:00
Showing only changes of commit a16d9bf82c - Show all commits

View file

@ -178,7 +178,7 @@ class Network():
def reset_vlan_on_interface(self, nic, interface): def reset_vlan_on_interface(self, nic, interface):
update = False update = False
vlan_id = nic['vlan'] vlan_id = nic['vlan']
lldp_vlan = self.lldp.get_switch_vlan(nic['name']) lldp_vlan = self.lldp.get_switch_vlan(nic['name']) if NETWORK_LLDP else None
# if local interface isn't a interface vlan or lldp doesn't report a vlan-id # if local interface isn't a interface vlan or lldp doesn't report a vlan-id
if vlan_id is None and lldp_vlan is None and \ if vlan_id is None and lldp_vlan is None and \
@ -264,12 +264,13 @@ class Network():
type=type, type=type,
mgmt_only=mgmt, mgmt_only=mgmt,
) )
if nic['vlan']: if nic['vlan']:
nb_vlan = self.get_or_create_vlan(nic['vlan']) nb_vlan = self.get_or_create_vlan(nic['vlan'])
interface.mode = 200 interface.mode = 200
interface.tagged_vlans = [nb_vlan.id] interface.tagged_vlans = [nb_vlan.id]
interface.save() interface.save()
elif self.lldp.get_switch_vlan(nic['name']) is not None: elif NETWORK_LLDP and self.lldp.get_switch_vlan(nic['name']) is not None:
# if lldp reports a vlan on an interface, tag the interface in access and set the vlan # if lldp reports a vlan on an interface, tag the interface in access and set the vlan
vlan_id = self.lldp.get_switch_vlan(nic['name']) vlan_id = self.lldp.get_switch_vlan(nic['name'])
nb_vlan = self.get_or_create_vlan(vlan_id) nb_vlan = self.get_or_create_vlan(vlan_id)
@ -511,8 +512,7 @@ class Network():
ret, interface = self.create_or_update_cable( ret, interface = self.create_or_update_cable(
switch_ip, switch_interface, interface switch_ip, switch_interface, interface
) )
if ret: nic_update += ret
nic_update += 1
if nic['ip']: if nic['ip']:
# sync local IPs # sync local IPs