Skip to content

Commit caa39c7

Browse files
authored
Implement icon selection based on Device Role (#14)
* Implement icon selection based on Device Role Icon selection criteria order: 1. Based on 'icon_{icon_type}' tag in Netbox device 2. Based on Netbox device type and ICON_MODEL_MAP 3. Based on Netbox device role and ICON_ROLE_MAP 4. Default 'undefined' The plugin contains a default Device Role to Icon mapping: DEFAULT_ICON_ROLE_MAP = { 'border': 'router', 'edge-switch': 'switch', 'edge-router': 'router', 'core-router': 'router', 'core-switch': 'switch', 'distribution': 'switch', 'distribution-router': 'router', 'distribution-switch': 'switch', 'leaf': 'switch', 'spine': 'switch', 'access': 'switch', 'access-switch': 'switch', } A custom Device Role to Icon mapping may be defined in 'icon_role_map' plugin parameter within Netbox configuration file. * Update README.md * v0.5.0 Co-authored-by: Debug All <iDebugAll@gmail.com>
1 parent c5cb32e commit caa39c7

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Optionally, update a PLUGINS_CONFIG parameter in **configuration.py** to rewrite
5050
# ADD YOUR SETTINGS HERE
5151
# icon_model_map is a dict
5252
# },
53+
# 'icon_role_map': {
54+
# ADD YOUR SETTINGS HERE
55+
# icon_role_map is a dict
56+
# }
5357
# 'undisplayed_device_role_slugs': (
5458
# # ADD YOUR SETTINGS HERE
5559
# undisplayed_device_role_slugs value is a list or a tuple
@@ -136,9 +140,29 @@ By default, the Plugin automatically tries to identify the device icon type base
136140
'ASA': 'firewall',
137141
}
138142
```
139-
Keys are searched substrings. Values should be valid icon types as listed above.
143+
Keys are searched substrings. Values should be valid icon types as listed above.<br/>
144+
145+
3. If no match found on steps 1-2, the Plugin checks the Device Role to Icon mapping.<br/>
146+
This mapping may be defined within 'icon_role_map' dict in Plugin parameters.<br/>
147+
Default mapping already contains some general categories:
148+
```
149+
{
150+
'border': 'router',
151+
'edge-switch': 'switch',
152+
'edge-router': 'router',
153+
'core-router': 'router',
154+
'core-switch': 'switch',
155+
'distribution': 'switch',
156+
'distribution-router': 'router',
157+
'distribution-switch': 'switch',
158+
'leaf': 'switch',
159+
'spine': 'switch',
160+
'access': 'switch',
161+
'access-switch': 'switch',
162+
}
163+
```
140164

141-
3. Default value is 'unknown' (renders as a question mark icon).
165+
4. Default value is 'unknown' (renders as a question mark icon).
142166
<br/><br/>
143167

144168
The Plugin can control the visibility of the layers and/or specific nodes on the topology view.<br/>

nextbox_ui_plugin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class NextBoxUIConfig(PluginConfig):
44
name = 'nextbox_ui_plugin'
55
verbose_name = 'NextBox UI'
66
description = 'Test'
7-
version = '0.4.5'
7+
version = '0.5.0'
88
author = 'Igor Korotchenkov'
99
author_email = 'iDebugAll@gmail.com'
1010
base_url = 'nextbox-ui'

nextbox_ui_plugin/views.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@
8888
}
8989

9090

91+
DEFAULT_ICON_ROLE_MAP = {
92+
'border': 'router',
93+
'edge-switch': 'switch',
94+
'edge-router': 'router',
95+
'core-router': 'router',
96+
'core-switch': 'switch',
97+
'distribution': 'switch',
98+
'distribution-router': 'router',
99+
'distribution-switch': 'switch',
100+
'leaf': 'switch',
101+
'spine': 'switch',
102+
'access': 'switch',
103+
'access-switch': 'switch',
104+
}
105+
106+
91107
PLUGIN_SETTINGS = settings.PLUGINS_CONFIG.get("nextbox_ui_plugin", dict())
92108

93109
MANUAL_LAYERS_SORT_ORDER = PLUGIN_SETTINGS.get("layers_sort_order", "")
@@ -96,6 +112,9 @@
96112
MANUAL_ICON_MODEL_MAP = PLUGIN_SETTINGS.get("icon_model_map", "")
97113
ICON_MODEL_MAP = MANUAL_ICON_MODEL_MAP or DEFAULT_ICON_MODEL_MAP
98114

115+
MANUAL_ICON_ROLE_MAP = PLUGIN_SETTINGS.get("icon_role_map", "")
116+
ICON_ROLE_MAP = MANUAL_ICON_ROLE_MAP or DEFAULT_ICON_ROLE_MAP
117+
99118
# Defines whether Devices with no connections
100119
# are displayed on the topology view by default or not.
101120
DISPLAY_UNCONNECTED = PLUGIN_SETTINGS.get("DISPLAY_UNCONNECTED", True)
@@ -146,7 +165,8 @@ def get_icon_type(device_id):
146165
Selection order:
147166
1. Based on 'icon_{icon_type}' tag in Netbox device
148167
2. Based on Netbox device type and ICON_MODEL_MAP
149-
3. Default 'undefined'
168+
3. Based on Netbox device role and ICON_ROLE_MAP
169+
4. Default 'undefined'
150170
"""
151171
nb_device = Device.objects.get(id=device_id)
152172
if not nb_device:
@@ -158,6 +178,9 @@ def get_icon_type(device_id):
158178
for model_base, icon_type in ICON_MODEL_MAP.items():
159179
if model_base in str(nb_device.device_type.model):
160180
return icon_type
181+
for role_slug, icon_type in ICON_ROLE_MAP.items():
182+
if str(nb_device.device_role.slug) == role_slug:
183+
return icon_type
161184
return 'unknown'
162185

163186

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
setup(
99
name='nextbox_ui_plugin',
10-
version='0.4.5',
10+
version='0.5.0',
1111
url='https://github.com/iDebugAll/nextbox-ui-plugin',
12-
download_url='https://github.com/iDebugAll/nextbox-ui-plugin/archive/v0.4.5.tar.gz',
12+
download_url='https://github.com/iDebugAll/nextbox-ui-plugin/archive/v0.5.0.tar.gz',
1313
description='A topology visualization plugin for Netbox powered by NextUI Toolkit.',
1414
long_description=long_description,
1515
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)