Skip to content

Commit

Permalink
Do not add VID 0 to diffsync store (#283)
Browse files Browse the repository at this point in the history
* Do not add VID 0 to diffsync store
* adjust to only not add when id of 0, rather than blank
  • Loading branch information
scetron authored Dec 14, 2024
1 parent 4c66d03 commit af88913
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
1 change: 1 addition & 0 deletions changes/283.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed adding invalid VLAN 0 to Diffsync Store causing Sync Data job to fail.
Original file line number Diff line number Diff line change
Expand Up @@ -602,26 +602,28 @@ def load_vlans(self):
model_type="vlan",
)
continue
# check for untagged vlan and add if necessary
if interface_data["untagged_vlan"]:
try:
network_vlan = self.vlan(
adapter=self,
name=interface_data["untagged_vlan"]["name"],
vid=interface_data["untagged_vlan"]["id"],
location__name=location_names.get(hostname, ""),
)
self.add(network_vlan)
except diffsync.exceptions.ObjectAlreadyExists:
continue
except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err,
hostname=hostname,
data=device_data,
model_type="vlan",
)
continue
# check for untagged vlan and add if necessary, skip VLAN 0
if interface_data["untagged_vlan"] and interface_data["untagged_vlan"].get("id") == "0":
self.job.logger.warning("Interface with untagged vlan 0 found. Skipping untagged vlan load.")
continue
try:
network_vlan = self.vlan(
adapter=self,
name=interface_data["untagged_vlan"]["name"],
vid=interface_data["untagged_vlan"]["id"],
location__name=location_names.get(hostname, ""),
)
self.add(network_vlan)
except diffsync.exceptions.ObjectAlreadyExists:
continue
except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err,
hostname=hostname,
data=device_data,
model_type="vlan",
)
continue

def load_vrfs(self):
"""Load vrfs into the Diffsync store."""
Expand Down Expand Up @@ -711,13 +713,17 @@ def load_untagged_vlan_to_interface(self):
# for interface in device_data["interfaces"]:
for interface_name, interface_data in device_data["interfaces"].items():
try:
if interface_data["untagged_vlan"] and interface_data["untagged_vlan"].get("id") == "0":
self.job.logger.warning("Interface with untagged vlan 0 found. Skipping untagged vlan load.")
continue
network_untagged_vlan_to_interface = self.untagged_vlan_to_interface(
adapter=self,
device__name=hostname,
name=interface_name,
untagged_vlan=interface_data["untagged_vlan"],
)
self.add(network_untagged_vlan_to_interface)

except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err,
Expand Down

0 comments on commit af88913

Please sign in to comment.