Skip to content

Commit

Permalink
Merge pull request #287 from nautobot/patch-add_settings_check_cvp
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrew82 authored Dec 1, 2023
2 parents b25f4dd + 153c981 commit fd724ed
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create(cls, diffsync, ids, attrs):
new_device = OrmDevice(
status=OrmStatus.objects.get(name=attrs["status"]),
device_type=device_type_object,
device_role=role,
role=role,
platform=platform,
site=site,
name=ids["name"],
Expand Down
24 changes: 24 additions & 0 deletions nautobot_ssot/integrations/aristacv/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
name = "SSoT - Arista CloudVision" # pylint: disable=invalid-name


class MissingConfigSetting(Exception):
"""Exception raised for missing configuration settings.
Attributes:
message (str): Returned explanation of Error.
"""

def __init__(self, setting):
"""Initialize Exception with Setting that is missing and message."""
self.setting = setting
self.message = f"Missing configuration setting - {setting}!"
super().__init__(self.message)


class CloudVisionDataSource(DataSource, Job): # pylint: disable=abstract-method
"""CloudVision SSoT Data Source."""

Expand Down Expand Up @@ -84,6 +98,16 @@ def data_mappings(cls):

def load_source_adapter(self):
"""Load data from CloudVision into DiffSync models."""
if not APP_SETTINGS.get("from_cloudvision_default_site"):
self.logger.error(
"App setting `aristacv_from_cloudvision_default_site` is not defined. This setting is required for the App to function."
)
raise MissingConfigSetting(setting="aristacv_from_cloudvision_default_site")
if not APP_SETTINGS.get("from_cloudvision_default_device_role"):
self.logger.error(
"App setting `aristacv_from_cloudvision_default_device_role` is not defined. This setting is required for the App to function."
)
raise MissingConfigSetting(setting="aristacv_from_cloudvision_default_device_role")
if self.debug:
if APP_SETTINGS.get("delete_devices_on_sync"):
self.logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def process_ext_attrs(diffsync, obj: object, extattrs: dict):
f"Unable to find Tenant {attr_value} for {obj} found in Extensibility Attributes '{attr}'. {err}"
)
_cf_dict = {
"key": slugify(attr),
"key": slugify(attr).replace("-", "_"),
"type": CustomFieldTypeChoices.TYPE_TEXT,
"label": attr,
}
Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot/integrations/infoblox/utils/diffsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_ext_attr_dict(extattrs: dict):
"""
fixed_dict = {}
for key, value in extattrs.items():
fixed_dict[slugify(key)] = value["value"]
fixed_dict[slugify(key).replace("-", "_")] = value["value"]
return fixed_dict


Expand Down
4 changes: 2 additions & 2 deletions nautobot_ssot/tests/ipfabric/test_nautobot_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
# device_role = DeviceRole.objects.create(name="Router", slug="router")

# Device.objects.create(
# name="csr1", device_type=device_type, device_role=device_role, site=site_1, status=status_active
# name="csr1", device_type=device_type, role=device_role, site=site_1, status=status_active
# )
# Device.objects.create(
# name="csr2", device_type=device_type, device_role=device_role, site=site_2, status=status_active
# name="csr2", device_type=device_type, role=device_role, site=site_2, status=status_active
# )

# VLAN.objects.create(name="VLAN101", vid=101, status=status_active, site=site_1)
Expand Down

0 comments on commit fd724ed

Please sign in to comment.