Skip to content

Add option to hide interfaces with specific names. #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions nextbox_ui_plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
# Hide devices tagged with these tags
UNDISPLAYED_DEVICE_TAGS = PLUGIN_SETTINGS.get("undisplayed_device_tags", tuple())

# Hide interfaces with specific names.
UNDISPLAYED_INTERFACE_NAMES = PLUGIN_SETTINGS.get("undisplayed_interface_names", tuple())

# Filter device tags listed in Select Layers menu
SELECT_LAYERS_LIST_INCLUDE_DEVICE_TAGS = PLUGIN_SETTINGS.get("select_layers_list_include_device_tags", tuple())
SELECT_LAYERS_LIST_EXCLUDE_DEVICE_TAGS = PLUGIN_SETTINGS.get("select_layers_list_exclude_device_tags", tuple())
Expand Down Expand Up @@ -240,14 +243,19 @@ def get_vlan_topology(nb_devices_qs, vlans):
filtred_devices = [d.id for d in nb_devices_qs]
filtred_interfaces = []
for interface in interfaces:
if interface.is_connectable:
if hasattr(interface, 'is_connectable') and interface.is_connectable:
direct_device_id = interface.device.id
interface_trace = interface.trace()
if len(interface_trace) != 0:
termination_b_iface = interface_trace[-1][-1]
connected_device_id = termination_b_iface.device.id
if (direct_device_id in filtred_devices) or (direct_device_id in filtred_devices):
filtred_interfaces.append(interface)

if (
interface.name.lower() not in UNDISPLAYED_INTERFACE_NAMES
and termination_b_iface.name.lower() not in UNDISPLAYED_INTERFACE_NAMES
):
connected_device_id = termination_b_iface.device.id
if (direct_device_id in filtred_devices) or (direct_device_id in filtred_devices):
filtred_interfaces.append(interface)



Expand Down Expand Up @@ -295,11 +303,12 @@ def get_vlan_topology(nb_devices_qs, vlans):

mapped_links = []
for interface in filtred_interfaces:
if interface.is_connectable:
if hasattr(interface, 'is_connectable') and interface.is_connectable:
interface_trace = interface.trace()
if len(interface_trace) != 0:
source_cable = interface_trace[0]
dest_cable = interface_trace[-1]

mapping_link = [source_cable[0].device.id,dest_cable[-1].device.id]
if (mapping_link not in mapped_links) and (mapping_link.reverse() not in mapped_links):
mapped_links.append(mapping_link)
Expand Down Expand Up @@ -396,16 +405,16 @@ def get_topology(nb_devices_qs):
if not links_from_device:
continue
for link in links_from_device:
if NETBOX_CURRENT_VERSION < version.parse("3.3"):
# Include links to discovered devices only
if link._termination_b_device_id in device_ids:
links.append(link)
else:
# Exclude PowerFeed-connected links
if (isinstance(link.a_terminations[0], PowerFeed) or (isinstance(link.b_terminations[0], PowerFeed))):
continue
# Include links to discovered devices only
if link.b_terminations[0].device_id in device_ids:
# Exclude PowerFeed-connected links
if (isinstance(link.a_terminations[0], PowerFeed) or (isinstance(link.b_terminations[0], PowerFeed))):
continue

# Include links to discovered devices only
if link.b_terminations[0].device_id in device_ids:
if (
link.a_terminations[0].name.lower() not in UNDISPLAYED_INTERFACE_NAMES
and link.b_terminations[0].name.lower() not in UNDISPLAYED_INTERFACE_NAMES
):
links.append(link)

device_roles = list(device_roles)
Expand Down