Skip to content

Commit

Permalink
Merge pull request #607 from nautobot/patch-fix_citrix_hostname_mapping
Browse files Browse the repository at this point in the history
Fix hostname_mapping in Citrix ADM
  • Loading branch information
jdrew82 authored Nov 21, 2024
2 parents e344f02 + c757439 commit 2ea8bd3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
1 change: 1 addition & 0 deletions changes/607.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix hostname_mapping functionailty in Citrix ADM integration.
1 change: 1 addition & 0 deletions changes/607.housekeeping
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove redundant parse_hostname_for_role() function in Meraki integration that was missed in 599.
12 changes: 7 additions & 5 deletions nautobot_ssot/integrations/citrix_adm/jobs.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -50,10 +52,10 @@ 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'}.",
default={},
description="List of tuples containing Device hostname regex patterns to assign to specified Role. ex: [('.*ilb.*', 'Internal Load-Balancer')]",
default=[],
required=False,
)
tenant = ObjectVar(model=Tenant, queryset=Tenant.objects.all(), display_field="display_name", required=False)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions nautobot_ssot/integrations/meraki/diffsync/adapters/meraki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.")
Expand Down
20 changes: 0 additions & 20 deletions nautobot_ssot/integrations/meraki/utils/meraki.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Utility functions for working with Meraki."""

import re

import meraki


Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2ea8bd3

Please sign in to comment.