Skip to content

Commit

Permalink
replace slug field
Browse files Browse the repository at this point in the history
  • Loading branch information
lvrfrc87 committed Aug 21, 2023
1 parent 058856b commit 7e609ec
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions nautobot_plugin_nornir/plugins/inventory/nautobot_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ def create_host(self, device, cred, params: Dict):

if not device.platform:
raise NornirNautobotException(f"Platform missing from device {device.name}, preemptively failed.")
host["platform"] = device.platform.slug
host["platform"] = device.platform.network_driver
host["data"]["id"] = device.id
host["data"]["type"] = device.device_type.slug
host["data"]["location"] = device.location.slug
host["data"]["role"] = device.role.slug
host["data"]["type"] = device.device_type.model
host["data"]["location"] = device.location.name
host["data"]["role"] = device.role.name
host["data"]["config_context"] = dict(device.get_config_context())
host["data"]["custom_field_data"] = device.custom_field_data
host["data"]["obj"] = device
Expand Down Expand Up @@ -234,16 +234,16 @@ def get_host_groups(device):
"""
groups = [
"global",
f"location__{device.location.slug}",
f"role__{device.role.slug}",
f"type__{device.device_type.slug}",
f"manufacturer__{device.device_type.manufacturer.slug}",
f"location__{device.location.name}",

This comment has been minimized.

Copy link
@itdependsnetworks

itdependsnetworks Aug 22, 2023

Contributor

This will likely break with special characters. Same for others with name.

This comment has been minimized.

Copy link
@lvrfrc87

lvrfrc87 Aug 22, 2023

Author Contributor

Ok. What should we use instead?

This comment has been minimized.

Copy link
@glennmatthews

glennmatthews Aug 22, 2023

Could explicitly slugify() the names, perhaps?

This comment has been minimized.

Copy link
@itdependsnetworks

itdependsnetworks Aug 22, 2023

Contributor

That makes sense, however we would need to add some validation that no 2 entries can have the same slugified names, as presumably it is possible to have “site nyc” and “site-nyc” that would be slugified the same.

This comment has been minimized.

Copy link
@glennmatthews

glennmatthews Aug 22, 2023

That's a problem with any translation or remapping of strings though.

This comment has been minimized.

Copy link
@itdependsnetworks

itdependsnetworks Aug 22, 2023

Contributor

Understood, just trying to be explicit as it may not be clear to everyone.

f"role__{device.role.name}",
f"type__{device.device_type.model}",
f"manufacturer__{device.device_type.manufacturer.name}",
]

if device.platform:
groups.append(f"platform__{device.platform.slug}")
groups.append(f"platform__{device.platform.network_driver}")

if device.tenant:
groups.append(f"tenant__{device.tenant.slug}")
groups.append(f"tenant__{device.tenant.name}")

return groups

0 comments on commit 7e609ec

Please sign in to comment.