Skip to content

Commit

Permalink
Merge pull request #255 from smk4664/next-2.0
Browse files Browse the repository at this point in the history
Next 2.0
  • Loading branch information
smk4664 authored Sep 13, 2023
2 parents b32e92c + 2732209 commit fe0f2bf
Show file tree
Hide file tree
Showing 47 changed files with 900 additions and 1,129 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.9", "3.10"]
nautobot-version: ["1.5.4", "stable"]
python-version: ["3.10"]
nautobot-version: ["2.0.0-rc.2"]
runs-on: "ubuntu-20.04"
env:
INVOKE_NAUTOBOT_CHATOPS_PYTHON_VER: "${{ matrix.python-version }}"
Expand Down
2 changes: 1 addition & 1 deletion development/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ NAUTOBOT_CHATOPS_ENABLE_WEBEX="False"
NAUTOBOT_CHATOPS_ENABLE_ACI="False"

# - AWX / Ansible Tower --------------
NAUTOBOT_CHATOPS_ENABLE_ANSIBLE="True"
NAUTOBOT_CHATOPS_ENABLE_ANSIBLE="False"
NAUTOBOT_TOWER_URI="https://awx:8043/"
NAUTOBOT_TOWER_USERNAME="awx"
NAUTOBOT_TOWER_VERIFY_SSL="False"
Expand Down
17 changes: 17 additions & 0 deletions development/docker-compose.socket.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
version: "3.8"
services:
socket:
image: "nautobot-chatops-plugin/nautobot:${NAUTOBOT_VER}-py${PYTHON_VER}"
env_file:
- "development.env"
- "creds.env"
tty: true
entrypoint: "nautobot-server start_slack_socket"
depends_on:
- "nautobot"
healthcheck:
disable: true
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
4 changes: 2 additions & 2 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

# Enable installed plugins. Add the name of each plugin to the list.
PLUGINS = [
"nautobot_capacity_metrics",
# "nautobot_capacity_metrics",
"nautobot_chatops",
]

Expand Down Expand Up @@ -211,4 +211,4 @@
},
}

METRICS_ENABLED = is_truthy(os.getenv("NAUTOBOT_METRICS_ENABLED"))
# METRICS_ENABLED = is_truthy(os.getenv("NAUTOBOT_METRICS_ENABLED"))
13 changes: 6 additions & 7 deletions docs/dev/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ the `handle_subcommands` helper function provided:
```python
# nautobot_chatops/workers/mycommand.py

from django_rq import job

from nautobot_chatops.workers import handle_subcommands, subcommand_of

@job("default")

def mycommand(subcommand, **kwargs)
"""Perform mycommand and its subcommands."""
return handle_subcommands("mycommand", subcommand, **kwargs)
Expand Down Expand Up @@ -110,11 +108,12 @@ and so the function needs to prompt the user for additional inputs, for example:

```python
@subcommand_of("nautobot")
def get_rack(dispatcher, site_slug, rack_id):
def get_rack(dispatcher, site_key, rack_id):
"""Get information about a specific rack from Nautobot."""
if not site_slug:
site_options = [(site.name, site.slug) for site in Site.objects.all()]
dispatcher.prompt_from_menu("nautobot get-rack", "Select a site", site_options)
site_lt = LocationType.objects.get(name="Site")
if not site_key:
site_options = [(site.name, site.composite_key) for site in Location.objects.filter(location_type=site_lt)]
dispatcher.prompt_from_menu("nautobot get-rack", "Select a site (location)", site_options)
return False # command did not run to completion and therefore should not be logged
...
```
Expand Down
2 changes: 0 additions & 2 deletions nautobot_chatops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ class NautobotChatOpsConfig(PluginConfig):
"panorama_user": "",
}

max_version = "1.999"
min_version = "1.5.4"
caching_config = {}

def ready(self):
Expand Down
30 changes: 0 additions & 30 deletions nautobot_chatops/api/nested_serializers.py

This file was deleted.

29 changes: 25 additions & 4 deletions nautobot_chatops/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from rest_framework import serializers

from nautobot.core.api import ValidatedModelSerializer
from nautobot.core.api import NautobotModelSerializer

from nautobot_chatops.models import AccessGrant, CommandToken
from nautobot_chatops.models import AccessGrant, CommandLog, CommandToken


class CommandTokenSerializer(ValidatedModelSerializer):
class CommandTokenSerializer(NautobotModelSerializer):
"""API serializer for interacting with CommandToken objects."""

url = serializers.HyperlinkedIdentityField(view_name="plugins-api:nautobot_chatops-api:commandtoken-detail")
Expand All @@ -19,7 +19,7 @@ class Meta:
fields = ("id", "comment", "platform", "token", "url")


class AccessGrantSerializer(ValidatedModelSerializer):
class AccessGrantSerializer(NautobotModelSerializer):
"""API serializer for interacting with AccessGrant objects."""

url = serializers.HyperlinkedIdentityField(view_name="plugins-api:nautobot_chatops-api:accessgrant-detail")
Expand All @@ -29,3 +29,24 @@ class Meta:

model = AccessGrant
fields = ("id", "command", "subcommand", "grant_type", "name", "value", "url")


class CommandLogSerializer(NautobotModelSerializer):
"""API serializer for interacting with CommandLog objects."""

class Meta:
"""Meta for CommandLog Serializer."""

model = CommandLog
fields = (
"id",
"start_time",
"user_name",
"user_id",
"platform",
"command",
"subcommand",
"params",
"status",
"details",
)
10 changes: 8 additions & 2 deletions nautobot_chatops/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

from django.conf import settings
from django.urls import include, path
from nautobot.core.api import OrderedDefaultRouter
from nautobot_chatops.api.views.generic import AccessGrantViewSet, CommandTokenViewSet, NautobotChatopsRootView
from nautobot.apps.api import OrderedDefaultRouter
from nautobot_chatops.api.views.generic import (
AccessGrantViewSet,
CommandLogViewSet,
CommandTokenViewSet,
NautobotChatopsRootView,
)
from nautobot_chatops.api.views.lookup import AccessLookupView

_APP_CONFIG: Dict = settings.PLUGINS_CONFIG["nautobot_chatops"]
Expand Down Expand Up @@ -49,6 +54,7 @@
router.APIRootView = NautobotChatopsRootView
router.register("commandtoken", CommandTokenViewSet)
router.register("accessgrant", AccessGrantViewSet)
router.register("commandlog", CommandLogViewSet)

app_name = "nautobot_chatops-api"

Expand Down
14 changes: 11 additions & 3 deletions nautobot_chatops/api/views/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from rest_framework.routers import APIRootView
from nautobot.core.api.views import ModelViewSet

from nautobot_chatops.api.serializers import AccessGrantSerializer, CommandTokenSerializer
from nautobot_chatops.models import AccessGrant, CommandToken
from nautobot_chatops.filters import AccessGrantFilterSet, CommandTokenFilterSet
from nautobot_chatops.api.serializers import AccessGrantSerializer, CommandLogSerializer, CommandTokenSerializer
from nautobot_chatops.models import AccessGrant, CommandToken, CommandLog
from nautobot_chatops.filters import AccessGrantFilterSet, CommandLogFilterSet, CommandTokenFilterSet


class NautobotChatopsRootView(APIRootView):
Expand All @@ -23,6 +23,14 @@ class CommandTokenViewSet(ModelViewSet): # pylint: disable=too-many-ancestors
filterset_class = CommandTokenFilterSet


class CommandLogViewSet(ModelViewSet):
"""API viewset for interacting with CommandLog objects."""

queryset = CommandLog.objects.all()
serializer_class = CommandLogSerializer
filterset_class = CommandLogFilterSet


class AccessGrantViewSet(ModelViewSet): # pylint: disable=too-many-ancestors
"""API viewset for interacting with AccessGrant objects."""

Expand Down
2 changes: 1 addition & 1 deletion nautobot_chatops/choices.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""ChoiceSet classes for Nautobot."""

from nautobot.utilities.choices import ChoiceSet
from nautobot.core.choices import ChoiceSet


class AccessGrantTypeChoices(ChoiceSet):
Expand Down
2 changes: 1 addition & 1 deletion nautobot_chatops/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Django FilterSet classes for Nautobot."""

from nautobot.utilities.filters import BaseFilterSet
from nautobot.core.filters import BaseFilterSet

from nautobot_chatops.models import CommandLog, AccessGrant, CommandToken

Expand Down
24 changes: 22 additions & 2 deletions nautobot_chatops/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from django import forms

from nautobot.utilities.forms import BootstrapMixin
from nautobot.core.forms import BootstrapMixin

from .models import AccessGrant, CommandToken
from .models import AccessGrant, CommandLog, CommandToken
from .choices import AccessGrantTypeChoices, CommandTokenPlatformChoices
from .constants import ACCESS_GRANT_COMMAND_HELP_TEXT, COMMAND_TOKEN_TOKEN_HELP_TEXT

Expand Down Expand Up @@ -45,6 +45,26 @@ class Meta:
fields = ("command", "subcommand", "grant_type", "name", "value")


class CommandLogFilterForm(BootstrapMixin, forms.ModelForm):
"""Form for filtering Command Logs."""

command = forms.CharField(required=False)
subcommand = forms.CharField(required=False)

class Meta:
"""Metaclass attributes of AccessGrantFilterForm."""

model = CommandLog

fields = [
"platform",
"command",
"subcommand",
"status",
"details",
]


class CommandTokenFilterForm(BootstrapMixin, forms.ModelForm):
"""Form for filtering ComandToken instances."""

Expand Down
4 changes: 2 additions & 2 deletions nautobot_chatops/integrations/aci/worker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Worker functions implementing Nautobot "aci" command and subcommands."""

from distutils.util import strtobool
from django.conf import settings
from nautobot.core.celery import nautobot_task
from nautobot.core.settings_funcs import is_truthy

from nautobot_chatops.choices import CommandStatusChoices
from nautobot_chatops.workers import subcommand_of, handle_subcommands
Expand All @@ -24,7 +24,7 @@ def _read_settings():
if "URI" in key:
creds[subkey]["base_uri"] = PLUGIN_SETTINGS["aci_creds"][key]
if "VERIFY" in key:
creds[subkey]["verify"] = bool(strtobool(PLUGIN_SETTINGS["aci_creds"][key]))
creds[subkey]["verify"] = is_truthy(PLUGIN_SETTINGS["aci_creds"][key])

choices = [(key, key) for key in creds]

Expand Down
2 changes: 0 additions & 2 deletions nautobot_chatops/integrations/ansible/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import yaml
from django.conf import settings
from django_rq import job
from nautobot_chatops.workers import handle_subcommands, subcommand_of

from .tower import Tower
Expand Down Expand Up @@ -37,7 +36,6 @@ def prompt_for_job_template(dispatcher, command):
return False


@job("default")
def ansible(subcommand, **kwargs):
"""Interact with Ansible Tower."""
return handle_subcommands("ansible", subcommand, **kwargs)
Expand Down
2 changes: 0 additions & 2 deletions nautobot_chatops/integrations/aristacv/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
from datetime import datetime, timedelta
import os
from django_rq import job
from nautobot_chatops.workers import subcommand_of, handle_subcommands # pylint: disable=import-error
from nautobot_chatops.choices import CommandStatusChoices # pylint: disable=import-error
from .cvpgrpcutils import get_device_tags
Expand Down Expand Up @@ -64,7 +63,6 @@ def check_credentials(dispatcher):
return True


@job("default")
def cloudvision(subcommand, **kwargs):
"""Interact with cloudvision."""
return handle_subcommands("cloudvision", subcommand, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion nautobot_chatops/integrations/grafana/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# from django.urls import path

from nautobot.core.api import OrderedDefaultRouter
from nautobot.apps.api import OrderedDefaultRouter
from nautobot_chatops.integrations.grafana.api.views.generic import NautobotPluginChatopsGrafanaRootView


Expand Down
Loading

0 comments on commit fe0f2bf

Please sign in to comment.