Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
pv2b committed May 24, 2024
2 parents 9ee9182 + 7d8dc96 commit bd35696
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 80 deletions.
14 changes: 8 additions & 6 deletions netbox_plugin_mclag/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from extras.plugins import PluginConfig
from netbox.plugins import PluginConfig


class NetBoxMcLagConfig(PluginConfig):
name = 'netbox_plugin_mclag'
verbose_name = 'Multi-Chassis LAG'
description = 'Manage Multi-Chassis Link Aggregation Groups in Netbox (MC-LAG / MLAG / vPC / etc)'
version = '0.1.1'
base_url = 'mclag'
name = "netbox_plugin_mclag"
verbose_name = "Multi-Chassis LAG"
description = "Manage Multi-Chassis Link Aggregation Groups in Netbox (MC-LAG / MLAG / vPC / etc)"
version = "0.1.1"
base_url = "mclag"


config = NetBoxMcLagConfig
33 changes: 15 additions & 18 deletions netbox_plugin_mclag/navigation.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
from django.conf import settings
from extras.plugins import PluginMenuButton, PluginMenuItem, PluginMenu
from utilities.choices import ButtonColorChoices
from netbox.plugins import PluginMenuButton, PluginMenuItem, PluginMenu


mc_domain_buttons = [
PluginMenuButton(
link='plugins:netbox_plugin_mclag:mcdomain_add',
title='Add',
icon_class='mdi mdi-plus-thick',
color=ButtonColorChoices.GREEN
link="plugins:netbox_plugin_mclag:mcdomain_add",
title="Add",
icon_class="mdi mdi-plus-thick"
)
]

mc_lag_buttons = [
PluginMenuButton(
link='plugins:netbox_plugin_mclag:mclag_add',
title='Add',
icon_class='mdi mdi-plus-thick',
color=ButtonColorChoices.GREEN
link="plugins:netbox_plugin_mclag:mclag_add",
title="Add",
icon_class="mdi mdi-plus-thick"
)
]

_menu_items = (
PluginMenuItem(
link='plugins:netbox_plugin_mclag:mcdomain_list',
link_text='Multi-Chassis Domains',
buttons=mc_domain_buttons
link="plugins:netbox_plugin_mclag:mcdomain_list",
link_text="Multi-Chassis Domains",
buttons=mc_domain_buttons,
),
PluginMenuItem(
link='plugins:netbox_plugin_mclag:mclag_list',
link_text='Multi-Chassis LAGs',
buttons=mc_lag_buttons
link="plugins:netbox_plugin_mclag:mclag_list",
link_text="Multi-Chassis LAGs",
buttons=mc_lag_buttons,
),
)

plugin_settings = settings.PLUGINS_CONFIG.get('netbox_plugin_mclag', {})
plugin_settings = settings.PLUGINS_CONFIG.get("netbox_plugin_mclag", {})

if plugin_settings.get('top_level_menu'):
if plugin_settings.get("top_level_menu"):
menu = PluginMenu(
label="MC-LAG",
groups=(("MC-LAG", _menu_items),),
Expand Down
34 changes: 19 additions & 15 deletions netbox_plugin_mclag/template_content.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from extras.plugins import PluginTemplateExtension
from netbox.plugins import PluginTemplateExtension
from .models import McDomain, McLag
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist


class McLagInterfaceExtensions(PluginTemplateExtension):
model="dcim.interface"
model = "dcim.interface"

def buttons(self):
interface = self.context['object']
interface = self.context["object"]

if interface.type != 'lag':
if interface.type != "lag":
interface = interface.lag

if interface is None:
Expand All @@ -24,16 +26,17 @@ def buttons(self):
except ObjectDoesNotExist:
return ""

return self.render('netbox_plugin_mclag/button.html', extra_context={
'url': url,
'title': title
})
return self.render(
"netbox_plugin_mclag/button.html",
extra_context={"url": url, "title": title},
)


class McLagDeviceExtensions(PluginTemplateExtension):
model="dcim.device"
model = "dcim.device"

def buttons(self):
device = self.context['object']
device = self.context["object"]

try:
mc_domain = device.mc_domains.get()
Expand All @@ -45,9 +48,10 @@ def buttons(self):
except ObjectDoesNotExist:
return ""

return self.render('netbox_plugin_mclag/button.html', extra_context={
'url': url,
'title': title
})
return self.render(
"netbox_plugin_mclag/button.html",
extra_context={"url": url, "title": title},
)


template_extensions = [McLagInterfaceExtensions, McLagDeviceExtensions]
template_extensions = [McLagInterfaceExtensions, McLagDeviceExtensions]
4 changes: 2 additions & 2 deletions netbox_plugin_mclag/templates/netbox_plugin_mclag/button.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if url and title %}
<a role="button" class="btn btn-sm btn-primary" title="{{ title }}" href="{{ url }}">
<a role="button" class="btn btn-primary" title="{{ title }}" href="{{ url }}">
<i class="mdi mdi-switch" aria-hidden="true"></i>
{{ title }}
</a>
{% endif %}
{% endif %}
32 changes: 15 additions & 17 deletions netbox_plugin_mclag/templates/netbox_plugin_mclag/mcdomain.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">Access List</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description | placeholder }}</td>
</tr>
<tr>
<th scope="row">Domain ID</th>
<td>{{ object.domain_id }}</td>
</tr>
</table>
</div>
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description | placeholder }}</td>
</tr>
<tr>
<th scope="row">Domain ID</th>
<td>{{ object.domain_id }}</td>
</tr>
</table>
</div>
{% include 'inc/panels/custom_fields.html' %}
</div>
Expand All @@ -40,4 +38,4 @@ <h5 class="card-header">Multi-Chassis Link Aggregation Groups</h5>
</div>
</div>
</div>
{% endblock content %}
{% endblock content %}
42 changes: 20 additions & 22 deletions netbox_plugin_mclag/templates/netbox_plugin_mclag/mclag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">Multi-Chassis Link Aggregation Group</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description | placeholder }}</td>
</tr>
<tr>
<th scope="row">Multi-Chassis Domain</th>
<td>
<a href="{{ object.mc_domain.get_absolute_url }}">{{ object.mc_domain }}</a>
</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description | placeholder }}</td>
</tr>
<tr>
<th scope="row">Multi-Chassis Domain</th>
<td>
<a href="{{ object.mc_domain.get_absolute_url }}">{{ object.mc_domain }}</a>
</td>
</tr>
<tr>
<th scope="row">Group ID</th>
<td>{{ object.lag_id }}</td>
</tr>
</table>
</div>
<tr>
<th scope="row">Group ID</th>
<td>{{ object.lag_id }}</td>
</tr>
</table>
</div>
</div>
<div class="col col-md-6">
Expand All @@ -51,4 +49,4 @@ <h5 class="card-header">Member Physical Interfaces</h5>
</div>
</div>
</div>
{% endblock content %}
{% endblock content %}

0 comments on commit bd35696

Please sign in to comment.