-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NSO integration - initial commit
- Loading branch information
Showing
32 changed files
with
1,955 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Custom Exceptions for the nautobot_plugin_chatops_nso plugin.""" | ||
|
||
|
||
class CommunicationError(Exception): | ||
"""Error communicating with NSO.""" | ||
|
||
|
||
class DeviceNotFound(Exception): | ||
"""Device not found in NSO.""" | ||
|
||
|
||
class DeviceNotSupported(Exception): | ||
"""Device not supported in NSO.""" | ||
|
||
|
||
class DeviceLocked(Exception): | ||
"""Device not reachable in NSO.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Forms for Nautobot.""" | ||
|
||
from django.forms import ModelForm, CharField | ||
from nautobot.utilities.forms import BootstrapMixin | ||
from nautobot.dcim.models.devices import Platform, DeviceRole | ||
from nautobot.utilities.forms import DynamicModelChoiceField | ||
from nautobot_plugin_chatops_nso.models import CommandFilter | ||
|
||
|
||
class CommandFilterForm(BootstrapMixin, ModelForm): | ||
"""Form for editing command filters.""" | ||
|
||
command = CharField( | ||
max_length=200, help_text=" Supports <a href='https://pythex.org/' target='_blank'>Regular Expression</a>." | ||
) | ||
device_role = DynamicModelChoiceField(queryset=DeviceRole.objects.all()) | ||
platform = DynamicModelChoiceField( | ||
queryset=Platform.objects.all(), | ||
) | ||
|
||
class Meta: | ||
"""Metaclass attributes of the command filters form.""" | ||
|
||
model = CommandFilter | ||
|
||
fields = ("command", "device_role", "platform") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Custom filters for nautobot_plugin_chatops_nso.""" | ||
from django_jinja import library | ||
from nautobot_plugin_chatops_nso.nso import NSOClient | ||
|
||
|
||
@library.filter | ||
def get_nso_sync_status(device_name): | ||
"""Pull NSO sync status for specified device.""" | ||
nso = NSOClient() | ||
try: | ||
response = nso.sync_status(device_name) | ||
return response | ||
except Exception: # pylint: disable=W0703 | ||
return "N/A" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Django models for recording user interactions with Nautobot.""" | ||
from django.db import models | ||
from nautobot.core.models import BaseModel | ||
|
||
|
||
class CommandFilter(BaseModel): | ||
"""An allowed command tied to a given object.""" | ||
|
||
command = models.CharField(max_length=200, help_text="Standard regex supported.") | ||
device_role = models.ForeignKey(to="extras.Role", on_delete=models.CASCADE) | ||
platform = models.ForeignKey(to="dcim.Platform", on_delete=models.CASCADE) | ||
|
||
def __str__(self): | ||
"""String representation of an CommandFilter.""" | ||
return f'cmd: "{self.command}; on: {self.device_role}:{self.platform}' | ||
|
||
class Meta: | ||
"""Meta-attributes of an CommandFilter.""" | ||
|
||
ordering = ["command", "device_role", "platform"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Custom navigation options for the nautobot_plugin_chatops_nso plugin.""" | ||
from nautobot.core.apps import NavMenuTab, NavMenuGroup, NavMenuItem, NavMenuButton | ||
from nautobot.utilities.choices import ButtonColorChoices | ||
|
||
menu_items = ( | ||
NavMenuTab( | ||
name="Plugins", | ||
groups=( | ||
NavMenuGroup( | ||
name="NSO ChatOps", | ||
weight=200, | ||
items=( | ||
NavMenuItem( | ||
link="plugins:nautobot_plugin_chatops_nso:commandfilter_list", | ||
name="Command Filters", | ||
permissions=[ | ||
"nautobot_plugin_chatops_nso.view_commandfilter", | ||
], | ||
buttons=( | ||
NavMenuButton( | ||
link="plugins:nautobot_plugin_chatops_nso:commandfilter_add", | ||
title="Command Filter", | ||
icon_class="mdi mdi-plus-thick", | ||
button_class=ButtonColorChoices.GREEN, | ||
permissions=[ | ||
"nautobot_plugin_chatops_nso.add_commandfilter", | ||
], | ||
), | ||
), | ||
), | ||
NavMenuItem( | ||
link="plugins:nautobot_plugin_chatops_nso:nso_page", | ||
name="NSO Instance Link", | ||
permissions=[], | ||
buttons=(), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
) |
Oops, something went wrong.