From 92f74ccaca6ca9772ceaed154104bd6943cc0b36 Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:13:44 -0600 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20hostname=5Fmapp?= =?UTF-8?q?ing=20option=20in=20Citrix=20ADM=20integration.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nautobot_ssot/integrations/citrix_adm/jobs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nautobot_ssot/integrations/citrix_adm/jobs.py b/nautobot_ssot/integrations/citrix_adm/jobs.py index 48acb18f..8fcd838f 100644 --- a/nautobot_ssot/integrations/citrix_adm/jobs.py +++ b/nautobot_ssot/integrations/citrix_adm/jobs.py @@ -1,11 +1,13 @@ """Jobs for Citrix ADM SSoT integration.""" +from ast import literal_eval + from diffsync.enum import DiffSyncFlags from django.templatetags.static import static from django.urls import reverse from nautobot.core.celery import register_jobs from nautobot.dcim.models import Location, LocationType -from nautobot.extras.jobs import BooleanVar, Job, JSONVar, MultiObjectVar, ObjectVar +from nautobot.extras.jobs import BooleanVar, Job, JSONVar, MultiObjectVar, ObjectVar, StringVar from nautobot.extras.models import ExternalIntegration from nautobot.tenancy.models import Tenant @@ -50,9 +52,9 @@ class CitrixAdmDataSource(DataSource, Job): # pylint: disable=too-many-instance default={}, required=False, ) - hostname_mapping = JSONVar( + hostname_mapping = StringVar( label="Hostname Mapping", - description="Mapping of Device hostname to Role. Ex: {'router01': 'router'}.", + description="List of tuples containing Device hostname regex patterns to assign to specified Role. ex: [('.*ilb.*', 'Internal Load-Balancer')]", default={}, required=False, ) @@ -135,7 +137,7 @@ def run( # pylint: disable=arguments-differ, too-many-arguments self.dc_loctype = kwargs["dc_loctype"] self.parent_location = kwargs["parent_location"] self.location_map = kwargs["location_map"] - self.hostname_mapping = kwargs["hostname_mapping"] + self.hostname_mapping = literal_eval(kwargs["hostname_mapping"]) self.validate_job_settings() self.memory_profiling = memory_profiling super().run(dryrun=self.dryrun, memory_profiling=self.memory_profiling, *args, **kwargs) From 3f3efe9301e365af9fa65148c9f63c181234bfe9 Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:18:42 -0600 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Remove=20d?= =?UTF-8?q?uplicate=20parse=5Fhostname=5Ffor=5Frole()=20in=20Meraki=20inte?= =?UTF-8?q?gration.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I missed this when I consolidated the functions in 599. --- .../meraki/diffsync/adapters/meraki.py | 7 +++++-- .../integrations/meraki/utils/meraki.py | 20 ------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/nautobot_ssot/integrations/meraki/diffsync/adapters/meraki.py b/nautobot_ssot/integrations/meraki/diffsync/adapters/meraki.py index 173f0fb0..1c7463cd 100644 --- a/nautobot_ssot/integrations/meraki/diffsync/adapters/meraki.py +++ b/nautobot_ssot/integrations/meraki/diffsync/adapters/meraki.py @@ -16,7 +16,8 @@ MerakiPrefix, MerakiPrefixLocation, ) -from nautobot_ssot.integrations.meraki.utils.meraki import get_role_from_devicetype, parse_hostname_for_role +from nautobot_ssot.integrations.meraki.utils.meraki import get_role_from_devicetype +from nautobot_ssot.utils import parse_hostname_for_role class MerakiAdapter(Adapter): @@ -97,7 +98,9 @@ def load_devices(self): # pylint: disable=too-many-branches if self.job.hostname_mapping and len(self.job.hostname_mapping) > 0: if self.job.debug: self.job.logger.debug(f"Parsing hostname for device {dev['name']} to determine role.") - role = parse_hostname_for_role(dev_hostname=dev["name"], hostname_map=self.job.hostname_mapping) + role = parse_hostname_for_role( + device_hostname=dev["name"], hostname_map=self.job.hostname_mapping, default_role="Unknown" + ) elif self.job.devicetype_mapping and len(self.job.devicetype_mapping) > 0: if self.job.debug: self.job.logger.debug(f"Parsing device model for device {dev['name']} to determine role.") diff --git a/nautobot_ssot/integrations/meraki/utils/meraki.py b/nautobot_ssot/integrations/meraki/utils/meraki.py index cfd58ede..158d5b49 100644 --- a/nautobot_ssot/integrations/meraki/utils/meraki.py +++ b/nautobot_ssot/integrations/meraki/utils/meraki.py @@ -1,7 +1,5 @@ """Utility functions for working with Meraki.""" -import re - import meraki @@ -205,24 +203,6 @@ def get_appliance_switchports(self, network_id: str) -> list: return ports -def parse_hostname_for_role(dev_hostname: str, hostname_map: dict) -> str: - """Parse device hostname to get Device Role. - - Args: - dev_hostname (str): Hostname of Device to determine role of. - hostname_map (dict): Dictionary of hostname's mapped to their Role. - - Returns: - str: Name of DeviceRole. Defaults to Unknown. - """ - dev_role = "Unknown" - for entry in hostname_map: - match = re.match(pattern=entry[0], string=dev_hostname) - if match: - dev_role = entry[1] - return dev_role - - def get_role_from_devicetype(dev_model: str, devicetype_map: dict) -> str: """Get Device Role using DeviceType from devicetype_mapping Setting. From d032b9552cf4741df37de8bda5d324ca8b39b03b Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:21:00 -0600 Subject: [PATCH 3/4] =?UTF-8?q?docs:=20=F0=9F=93=9D=20Add=20changelog=20sn?= =?UTF-8?q?ippets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changes/607.fixed | 1 + changes/607.housekeeping | 1 + 2 files changed, 2 insertions(+) create mode 100644 changes/607.fixed create mode 100644 changes/607.housekeeping diff --git a/changes/607.fixed b/changes/607.fixed new file mode 100644 index 00000000..e77637ae --- /dev/null +++ b/changes/607.fixed @@ -0,0 +1 @@ +Fix hostname_mapping functionailty in Citrix ADM integration. \ No newline at end of file diff --git a/changes/607.housekeeping b/changes/607.housekeeping new file mode 100644 index 00000000..dc6054ac --- /dev/null +++ b/changes/607.housekeeping @@ -0,0 +1 @@ +Remove redundant parse_hostname_for_role() function in Meraki integration that was missed in 599. \ No newline at end of file From c7574394eb8b3f4c81318d70f3e92b4faad4d6e2 Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:14:36 -0600 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Correct=20default=20t?= =?UTF-8?q?o=20be=20a=20list.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nautobot_ssot/integrations/citrix_adm/jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nautobot_ssot/integrations/citrix_adm/jobs.py b/nautobot_ssot/integrations/citrix_adm/jobs.py index 8fcd838f..cd3001e4 100644 --- a/nautobot_ssot/integrations/citrix_adm/jobs.py +++ b/nautobot_ssot/integrations/citrix_adm/jobs.py @@ -55,7 +55,7 @@ class CitrixAdmDataSource(DataSource, Job): # pylint: disable=too-many-instance hostname_mapping = StringVar( label="Hostname Mapping", description="List of tuples containing Device hostname regex patterns to assign to specified Role. ex: [('.*ilb.*', 'Internal Load-Balancer')]", - default={}, + default=[], required=False, ) tenant = ObjectVar(model=Tenant, queryset=Tenant.objects.all(), display_field="display_name", required=False)