From 097fe5c6855824795366dca263f1ab6ac4e6ff9f Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Jul 2025 15:07:37 +0200 Subject: [PATCH] added some label items (#656) --- netbox_topology_views/choices.py | 20 ++++++++++++++++++++ netbox_topology_views/views.py | 12 +++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/netbox_topology_views/choices.py b/netbox_topology_views/choices.py index 0e0ba7f..5409fdb 100644 --- a/netbox_topology_views/choices.py +++ b/netbox_topology_views/choices.py @@ -2,13 +2,33 @@ from utilities.choices import ChoiceSet class NodeLabelItems(ChoiceSet): DEVICE_NAME = 'devicename' + DEVICE_TYPE = 'devicetype' + ROLE = 'role' + DESCRIPTION = 'description' PRIMARY_IPV4 = 'primaryipv4' PRIMARY_IPV6 = 'primaryipv6' OUT_OF_BAND_IP = 'outofbandip' + PLATFORM = 'platform' + SERIAL = 'serial' + TENANT = 'tenant' + SITE = 'site' + LOCATION = 'location' + RACK = 'rack' + VIRTUAL_CHASSIS = 'virtualchassis' CHOICES = [ (DEVICE_NAME, 'Device Name'), + (DEVICE_TYPE, 'Device Type'), + (ROLE, 'Role'), + (DESCRIPTION, 'Description'), (PRIMARY_IPV4, 'Primary IPv4'), (PRIMARY_IPV6, 'Primary IPv6'), (OUT_OF_BAND_IP, 'Out-of-band IP'), + (PLATFORM, 'Platform'), + (SERIAL, 'Serial'), + (TENANT, 'Tenant'), + (SITE, 'Site'), + (LOCATION, 'Location'), + (RACK, 'Rack'), + (VIRTUAL_CHASSIS, 'Virtual Chassis'), ] diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index cd817a5..1943d9a 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -236,14 +236,24 @@ def create_node( # Create a list of possible label items. Omit None types label_mapping = { NodeLabelItems.DEVICE_NAME: dev_name, + NodeLabelItems.DEVICE_TYPE: getattr(device, 'device_type', None), + NodeLabelItems.ROLE: getattr(device, 'role', None), + NodeLabelItems.DESCRIPTION: getattr(device, 'description', None), NodeLabelItems.PRIMARY_IPV4: getattr(device, 'primary_ip4', None), NodeLabelItems.PRIMARY_IPV6: getattr(device, 'primary_ip6', None), NodeLabelItems.OUT_OF_BAND_IP: getattr(device, 'oob_ip', None), + NodeLabelItems.PLATFORM: getattr(device, 'platform', None), + NodeLabelItems.SERIAL: getattr(device, 'serial', None), + NodeLabelItems.TENANT: getattr(device, 'tenant', None), + NodeLabelItems.SITE: getattr(device, 'site', None), + NodeLabelItems.LOCATION: getattr(device, 'location', None), + NodeLabelItems.RACK: getattr(device, 'rack', None), + NodeLabelItems.VIRTUAL_CHASSIS: getattr(device, 'virtual_chassis', None), } label_items = [] for item in node_label_items: - if label_mapping[item] is not None: + if label_mapping[item] and label_mapping[item] is not None: label_items.append(str(label_mapping[item])) node_label = '\n'.join(label_items)