network: fix vlan_id create multiple times

This commit is contained in:
bds-congnguyen 2022-07-31 00:53:31 +07:00
commit 4b0b3997f5

View file

@ -198,9 +198,6 @@ class Network(object):
def get_or_create_vlan(self, vlan_id):
# FIXME: we may need to specify the datacenter
# since users may have same vlan id in multiple dc
vlan = nb.ipam.vlans.get(
vid=vlan_id,
)
#/var/tmp/netbox-agent# lldpctl
# -------------------------------------------------------------------------------
# LLDP neighbors:
@ -217,6 +214,9 @@ class Network(object):
# on Cisco SMB, the vlan will be 4095 for port is member of Port-Channel instead of VLAN 1
if vlan_id == "4095":
vlan_id = "1"
vlan = nb.ipam.vlans.get(
vid=vlan_id,
)
if vlan is None:
vlan = nb.ipam.vlans.create(
name='VLAN {}'.format(vlan_id),