Skip to content

update to fix mtu int error #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/238.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a fix for mtu as an integer rather than a string.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from netutils.interface import canonical_interface_name

from nautobot_device_onboarding.diffsync.models import sync_network_data_models
from nautobot_device_onboarding.nornir_plays.command_getter import sync_network_data_command_getter
from nautobot_device_onboarding.nornir_plays.command_getter import (
sync_network_data_command_getter,
)
from nautobot_device_onboarding.utils import diffsync_utils

app_settings = settings.PLUGINS_CONFIG["nautobot_device_onboarding"]
Expand All @@ -29,7 +31,9 @@ class FilteredNautobotAdapter(NautobotAdapter):
def _load_objects(self, diffsync_model): # pylint: disable=protected-access
"""Given a diffsync model class, load a list of models from the database and return them."""
parameter_names = self._get_parameter_names(diffsync_model)
for database_object in diffsync_model._get_queryset(adapter=self): # pylint: disable=protected-access
for database_object in diffsync_model._get_queryset( # pylint: disable=protected-access
adapter=self
):
self._load_single_object(database_object, diffsync_model, parameter_names)


Expand Down Expand Up @@ -80,6 +84,12 @@ def load_param_mac_address(self, parameter_name, database_object):
return str(database_object.mac_address)
return ""

def load_param_mtu(self, parameter_name, database_object):
"""Convert interface mtu to string."""
if database_object.mtu:
return str(database_object.mtu)
return ""

def load_ip_addresses(self):
"""Load IP addresses into the DiffSync store.

Expand Down Expand Up @@ -440,7 +450,9 @@ def _handle_general_load_exception(self, error, hostname, data, model_type):
def execute_command_getter(self):
"""Query devices for data."""
result = sync_network_data_command_getter(
self.job.job_result, self.job.logger.getEffectiveLevel(), self.job.job_result.task_kwargs
self.job.job_result,
self.job.logger.getEffectiveLevel(),
self.job.job_result.task_kwargs,
)
# verify data returned is a dict
data_type_check = diffsync_utils.check_data_type(result)
Expand Down Expand Up @@ -495,7 +507,7 @@ def load_interface(self, hostname, interface_name, interface_data):
status__name=self.job.interface_status.name,
type=interface_data["type"],
mac_address=self._process_mac_address(mac_address=interface_data["mac_address"]),
mtu=interface_data["mtu"] if interface_data["mtu"] else 1500,
mtu=interface_data["mtu"] if interface_data["mtu"] else "1500",
description=interface_data["description"],
enabled=interface_data["link_status"],
mode=interface_data["802.1Q_mode"],
Expand All @@ -508,7 +520,10 @@ def load_interface(self, hostname, interface_name, interface_data):

def load_ip_addresses(self):
"""Load IP addresses into the DiffSync store."""
for hostname, device_data in self.job.command_getter_result.items(): # pylint: disable=too-many-nested-blocks
for ( # pylint: disable=too-many-nested-blocks
hostname,
device_data,
) in self.job.command_getter_result.items():
if self.job.debug:
self.job.logger.debug(f"Loading IP Addresses from {hostname}")
# for interface in device_data["interfaces"]:
Expand All @@ -534,9 +549,14 @@ def load_ip_addresses(self):
"DiffSync store. This is a duplicate IP Address."
)
continue
except Exception as err: # pylint: disable=broad-exception-caught
except (
Exception # pylint: disable=broad-exception-caught
) as err:
self._handle_general_load_exception(
error=err, hostname=hostname, data=device_data, model_type="ip_address"
error=err,
hostname=hostname,
data=device_data,
model_type="ip_address",
)
continue

Expand All @@ -546,7 +566,10 @@ def load_vlans(self):
for device in self.job.devices_to_load:
location_names[device.name] = device.location.name

for hostname, device_data in self.job.command_getter_result.items(): # pylint: disable=too-many-nested-blocks
for (
hostname,
device_data,
) in self.job.command_getter_result.items(): # pylint: disable=too-many-nested-blocks
if self.job.debug:
self.job.logger.debug(f"Loading Vlans from {hostname}")
# for interface in device_data["interfaces"]:
Expand All @@ -565,7 +588,10 @@ def load_vlans(self):
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"
error=err,
hostname=hostname,
data=device_data,
model_type="vlan",
)
continue
# check for untagged vlan and add if necessary
Expand All @@ -582,13 +608,19 @@ def load_vlans(self):
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"
error=err,
hostname=hostname,
data=device_data,
model_type="vlan",
)
continue

def load_vrfs(self):
"""Load vrfs into the Diffsync store."""
for hostname, device_data in self.job.command_getter_result.items(): # pylint: disable=too-many-nested-blocks
for (
hostname,
device_data,
) in self.job.command_getter_result.items(): # pylint: disable=too-many-nested-blocks
if self.job.debug:
self.job.logger.debug(f"Loading Vrfs from {hostname}")
# for interface in device_data["interfaces"]:
Expand All @@ -605,13 +637,19 @@ def load_vrfs(self):
continue
except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err, hostname=hostname, data=device_data, model_type="vrf"
error=err,
hostname=hostname,
data=device_data,
model_type="vrf",
)
continue

def load_ip_address_to_interfaces(self):
"""Load ip address interface assignments into the Diffsync store."""
for hostname, device_data in self.job.command_getter_result.items(): # pylint: disable=too-many-nested-blocks
for (
hostname,
device_data,
) in self.job.command_getter_result.items(): # pylint: disable=too-many-nested-blocks
for interface_name, interface_data in device_data["interfaces"].items():
for ip_address in interface_data["ip_addresses"]:
if ip_address["ip_address"]: # the ip_address and mask_length may be empty, skip these
Expand All @@ -626,9 +664,14 @@ def load_ip_address_to_interfaces(self):
),
)
self.add(network_ip_address_to_interface)
except Exception as err: # pylint: disable=broad-exception-caught
except (
Exception # pylint: disable=broad-exception-caught
) as err:
self._handle_general_load_exception(
error=err, hostname=hostname, data=device_data, model_type="ip_address to interface"
error=err,
hostname=hostname,
data=device_data,
model_type="ip_address to interface",
)
continue

Expand All @@ -647,7 +690,10 @@ def load_tagged_vlans_to_interface(self):
self.add(network_tagged_vlans_to_interface)
except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err, hostname=hostname, data=device_data, model_type="tagged vlan to interface"
error=err,
hostname=hostname,
data=device_data,
model_type="tagged vlan to interface",
)
continue

Expand All @@ -666,7 +712,10 @@ def load_untagged_vlan_to_interface(self):
self.add(network_untagged_vlan_to_interface)
except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err, hostname=hostname, data=device_data, model_type="untagged vlan to interface"
error=err,
hostname=hostname,
data=device_data,
model_type="untagged vlan to interface",
)
continue

Expand All @@ -680,12 +729,15 @@ def load_lag_to_interface(self):
adapter=self,
device__name=hostname,
name=interface_name,
lag__interface__name=interface_data["lag"] if interface_data["lag"] else "",
lag__interface__name=(interface_data["lag"] if interface_data["lag"] else ""),
)
self.add(network_lag_to_interface)
except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err, hostname=hostname, data=device_data, model_type="lag to interface"
error=err,
hostname=hostname,
data=device_data,
model_type="lag to interface",
)
continue

Expand All @@ -704,7 +756,10 @@ def load_vrf_to_interface(self):
self.add(network_vrf_to_interface)
except Exception as err: # pylint: disable=broad-exception-caught
self._handle_general_load_exception(
error=err, hostname=hostname, data=device_data, model_type="vrf to interface"
error=err,
hostname=hostname,
data=device_data,
model_type="vrf to interface",
)
continue

Expand Down