Skip to content

Commit

Permalink
Implement icon selection based on Device Role (#14)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
iDebugAll and iDebugAll authored Jun 8, 2020
1 parent c5cb32e commit caa39c7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Optionally, update a PLUGINS_CONFIG parameter in **configuration.py** to rewrite
# ADD YOUR SETTINGS HERE
# icon_model_map is a dict
# },
# 'icon_role_map': {
# ADD YOUR SETTINGS HERE
# icon_role_map is a dict
# }
# 'undisplayed_device_role_slugs': (
# # ADD YOUR SETTINGS HERE
# undisplayed_device_role_slugs value is a list or a tuple
Expand Down Expand Up @@ -136,9 +140,29 @@ By default, the Plugin automatically tries to identify the device icon type base
'ASA': 'firewall',
}
```
Keys are searched substrings. Values should be valid icon types as listed above.
Keys are searched substrings. Values should be valid icon types as listed above.<br/>

3. If no match found on steps 1-2, the Plugin checks the Device Role to Icon mapping.<br/>
This mapping may be defined within 'icon_role_map' dict in Plugin parameters.<br/>
Default mapping already contains some general categories:
```
{
'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',
}
```

3. Default value is 'unknown' (renders as a question mark icon).
4. Default value is 'unknown' (renders as a question mark icon).
<br/><br/>

The Plugin can control the visibility of the layers and/or specific nodes on the topology view.<br/>
Expand Down
2 changes: 1 addition & 1 deletion nextbox_ui_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class NextBoxUIConfig(PluginConfig):
name = 'nextbox_ui_plugin'
verbose_name = 'NextBox UI'
description = 'Test'
version = '0.4.5'
version = '0.5.0'
author = 'Igor Korotchenkov'
author_email = 'iDebugAll@gmail.com'
base_url = 'nextbox-ui'
Expand Down
25 changes: 24 additions & 1 deletion nextbox_ui_plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@
}


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',
}


PLUGIN_SETTINGS = settings.PLUGINS_CONFIG.get("nextbox_ui_plugin", dict())

MANUAL_LAYERS_SORT_ORDER = PLUGIN_SETTINGS.get("layers_sort_order", "")
Expand All @@ -96,6 +112,9 @@
MANUAL_ICON_MODEL_MAP = PLUGIN_SETTINGS.get("icon_model_map", "")
ICON_MODEL_MAP = MANUAL_ICON_MODEL_MAP or DEFAULT_ICON_MODEL_MAP

MANUAL_ICON_ROLE_MAP = PLUGIN_SETTINGS.get("icon_role_map", "")
ICON_ROLE_MAP = MANUAL_ICON_ROLE_MAP or DEFAULT_ICON_ROLE_MAP

# Defines whether Devices with no connections
# are displayed on the topology view by default or not.
DISPLAY_UNCONNECTED = PLUGIN_SETTINGS.get("DISPLAY_UNCONNECTED", True)
Expand Down Expand Up @@ -146,7 +165,8 @@ def get_icon_type(device_id):
Selection order:
1. Based on 'icon_{icon_type}' tag in Netbox device
2. Based on Netbox device type and ICON_MODEL_MAP
3. Default 'undefined'
3. Based on Netbox device role and ICON_ROLE_MAP
4. Default 'undefined'
"""
nb_device = Device.objects.get(id=device_id)
if not nb_device:
Expand All @@ -158,6 +178,9 @@ def get_icon_type(device_id):
for model_base, icon_type in ICON_MODEL_MAP.items():
if model_base in str(nb_device.device_type.model):
return icon_type
for role_slug, icon_type in ICON_ROLE_MAP.items():
if str(nb_device.device_role.slug) == role_slug:
return icon_type
return 'unknown'


Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

setup(
name='nextbox_ui_plugin',
version='0.4.5',
version='0.5.0',
url='https://github.com/iDebugAll/nextbox-ui-plugin',
download_url='https://github.com/iDebugAll/nextbox-ui-plugin/archive/v0.4.5.tar.gz',
download_url='https://github.com/iDebugAll/nextbox-ui-plugin/archive/v0.5.0.tar.gz',
description='A topology visualization plugin for Netbox powered by NextUI Toolkit.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit caa39c7

Please sign in to comment.