added some label items (#656)

This commit is contained in:
Mario
2025-07-17 15:07:37 +02:00
committed by GitHub
parent c83479fb1d
commit 097fe5c685
2 changed files with 31 additions and 1 deletions
+20
View File
@@ -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'),
]
+11 -1
View File
@@ -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)