Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from nautobot/develop
Browse files Browse the repository at this point in the history
Update main
  • Loading branch information
ubajze authored Aug 5, 2021
2 parents 7dc5de2 + b9677c5 commit 5dbd35d
Show file tree
Hide file tree
Showing 23 changed files with 1,256 additions and 735 deletions.
53 changes: 41 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---
stages:
- name: "test"
- name: "deploy-github"
if: "tag IS present"
- name: "deploy-pypi"
if: "tag IS present"

language: "python"
python:
- "3.6"
Expand All @@ -8,7 +15,7 @@ env:
# Each version of Nautobot listed here must have a corresponding directory/configuration file
# under development/nautobot_<NAUTOBOT_VER>/configuration.py
matrix:
- "INVOKE_NAUTOBOT-CHATOPS-EXTENSION-ARISTA_NAUTOBOT_VER=1.0.0"
- "INVOKE_NAUTOBOT_CHATOPS_EXTENSION_ARISTA_NAUTOBOT_VER=1.0.1"
# Add your encrypted secret below, you can encrypt secret using "travis encrypt"
# https://docs.travis-ci.com/user/environment-variables/#defining-encrypted-variables-in-travisyml
# global:
Expand All @@ -29,20 +36,42 @@ script:
# If you want to test different versions, it may require updating the poetry definition for Nautobot
# as that is where the version is controlled
# - "poetry add nautobot=$NAUTOBOT_VER"
- "INVOKE_NAUTOBOT-CHATOPS-EXTENSION-ARISTA_PYTHON_VER=$TRAVIS_PYTHON_VERSION invoke build --no-cache"
- "INVOKE_NAUTOBOT-CHATOPS-EXTENSION-ARISTA_PYTHON_VER=$TRAVIS_PYTHON_VERSION invoke tests --failfast"
- "INVOKE_NAUTOBOT_CHATOPS_EXTENSION_ARISTA_PYTHON_VER=$TRAVIS_PYTHON_VERSION invoke build --no-cache"
- "INVOKE_NAUTOBOT_CHATOPS_EXTENSION_ARISTA_PYTHON_VER=$TRAVIS_PYTHON_VERSION invoke tests --failfast"
# --------------------------------------------------------------------------
# Deploy
# Uncomment the section below if you would like to publish a new release to pypi automatically
# when a new tag is created in master. You"ll also need to generate a dedicated API key for this project in pypi
# and encrypt the key with "travis encrypt PYPI_TOKEN=<value> --add env.global --com"
# --------------------------------------------------------------------------
# deploy:
# provider: script
# script: poetry config pypi-token.pypi $PYPI_TOKEN && poetry publish --build
# skip_cleanup: true
# on:
# tags: true
# branch: master
# condition: $NAUTOBOT_VER = master
# python: 3.7
jobs:
include:
- stage: "deploy-github"
before_script:
- "pip install --upgrade pip"
- "pip install poetry"
script:
- "poetry version $TRAVIS_TAG"
- "poetry build"
deploy:
provider: "releases"
api_key: "$GITHUB_AUTH_TOKEN"
file_glob: true
file: "dist/*"
skip_cleanup: true
"on":
all_branches: true

- stage: "deploy-pypi"
before_script:
- "pip install --upgrade pip"
- "pip install poetry"
script:
- "echo Deploying the release to PyPI"
- "poetry version $TRAVIS_TAG"
deploy:
provider: "script"
skip_cleanup: true
script: "poetry publish --build -u __token__ -p $PYPI_TOKEN"
"on":
all_branches: true
115 changes: 82 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,94 @@
# Nautobot Chatops Extension Arista

A plugin for [Nautobot](https://github.com/nautobot/nautobot).
An extension for [Nautobot](https://github.com/nautobot/nautobot) [Chatops Plugin](https://github.com/nautobot/nautobot-plugin-chatops/)

## Installation

The plugin is available as a Python package in pypi and can be installed with pip
The extension is available as a Python package in PyPI and can be installed with pip

```shell
pip install nautobot-chatops-extension-arista
pip install git+https://github.com/nautobot/nautobot-plugin-chatops-arista-cloudvision.git
```

> The plugin is compatible with Nautobot 1.0.0 and higher
This ChatOps Extension to Nautobot ChatOps Plugin requires environment variables to be set up depending on if you are using a CVAAS (Cloudvision as a Service) or Cloudvision on-premise.

To ensure Nautobot Chatops Extension Arista is automatically re-installed during future upgrades, create a file named `local_requirements.txt` (if not already existing) in the Nautobot root directory (alongside `requirements.txt`) and list the `nautobot-chatops-extension-arista` package:
For CVAAS the following environment variables must be set.

```no-highlight
# echo nautobot-chatops-extension-arista >> local_requirements.txt
- `CVAAS_TOKEN`: Token generated from CVAAS service account. Documentation for that process can be found [here](https://www.arista.com/assets/data/pdf/qsg/qsg-books/QS_CloudVision_as_a_Service.pdf) in section 1.7

For on premise instance of Cloudvision, these environment variables must be set.

- `CVP_USERNAME`: The username that will be used to authenticate to Cloudvision.
- `CVP_PASSWORD`: The password for the configured username.
- `CVP_HOST`: The IP or hostname of the on premise Cloudvision appliance.
- `CVP_INSECURE`: If this is set to `True`, the appliance cert will be downloaded and automatically trusted. Otherwise, the appliance is expected to have a valid certificate.
- `ON_PREM`: By default this is set to False, this must be changed to `True` if using an on-prem instance of Cloudvision.

Once you have updated your environment file, restart both nautobot and nautobot-worker

```
$ sudo systemctl daemon-reload
$ sudo systemctl restart nautobot nautobot-worker
```

Once installed, the plugin needs to be enabled in your `nautobot_configuration.py`
## Usage

### Nautobot Config

You must first update the Nautobot configuration file with a new entry in the `PLUGINS_CONFIG` dictionary.

```python
# In your configuration.py
PLUGINS = ["nautobot_chatops_extension_arista"]

# PLUGINS_CONFIG = {
# "nautobot_chatops_extension_arista": {
# ADD YOUR SETTINGS HERE
# }
# }
PLUGINS_CONFIG = {
'nautobot_chatops': {
'enable_slack': True,
'slack_api_token': os.getenv("SLACK_API_TOKEN"),
'slack_signing_secret': os.getenv("SLACK_SIGNING_SECRET")
},
'nautobot_plugin_chatops_cloudvision' : {
'cvaas_token': os.getenv("CVAAS_TOKEN"),
'cvp_username': os.getenv("CVP_USERNAME"),
'cvp_password': os.getenv("CVP_PASSWORD"),
'cvp_host': os.getenv("CVP_HOST"),
"cvp_insecure": os.getenv("CVP_INSECURE"),
'on_prem': os.getenv("ON_PREM")
}
}
```

The plugin behavior can be controlled with the following list of settings
After that, you must update environment variables depending on if you are using a CVAAS (Cloudvision as a Service) or Cloudvision on-premise. To update environment variables in Nautobot check out our blog post [here](http://blog.networktocode.com/post/creating-custom-chat-commands-using-nautobot-chatops/)

- TODO
For CVAAS the following environment variables must be set.

## Usage
- `CVAAS_TOKEN`: Token generated from CVAAS service account. Documentation for that process can be found [here](https://www.arista.com/assets/data/pdf/qsg/qsg-books/QS_CloudVision_as_a_Service.pdf) in section 1.7

For on premise instance of Cloudvision, these environment variables must be set.

### API
- `CVP_USERNAME`: The username that will be used to authenticate to Cloudvision.
- `CVP_PASSWORD`: The password for the configured username.
- `CVP_HOST`: The IP or hostname of the on premise Cloudvision appliance.
- `CVP_INSECURE`: If this is set to `True`, the appliance cert will be downloaded and automatically trusted. Otherwise, the appliance is expected to have a valid certificate.
- `ON_PREM`: By default this is set to False, this must be changed to `True` if using an on-prem instance of Cloudvision.

TODO
Once you have updated your environment file, restart both nautobot and nautobot-worker

```
$ sudo systemctl daemon-reload
$ sudo systemctl restart nautobot nautobot-worker
```

### Command setup

Add a slash command to Slack called `/cloudvision`.
See the [nautobot-chatops installation guide](https://github.com/nautobot/nautobot-plugin-chatops/blob/develop/docs/chat_setup.md) for instructions on adding a slash command to your Slack channel.

The following commands are available:

- `get-devices-in-container [container-name]`: Retrieves all the devices assigned to the specificied container.
- `get-configlet [configlet-name]`: Get the configuration of the specified configlet.
- `get-device-configuration [device-name]`: Get the configuration of the specified device.
- `get-task-logs [task-id]`: Get the logs of the specified task.
- `get-applied-configlets [filter-type] [filter-value]`: Get applied configlets to either a specified container or device.
- `get-active-events [filter-type] [filter-value] [start-time] [end-time]`: Get active events in a given time frame. Filter-type can be filtered by device, type or severity. Filter-value is dynamically created based on the filter-type. Start-time accepts ISO time format as well as relative time inputs. Examples of that are `-2w`, `-2d`, `-2h` which will go back two weeks, two days and two hours, respectively.
- `get-applied-image-bundles [filter-type] [image-bundle-name]`: Gets the devices and containers an image bundle is applied to. Can also specify the `all` parameter to get a list of all the image bundles on Cloudvision.
- `get-device-cve [device-name]`: Gets all the CVEs of the specified device. Can also specifiy the `all` parameter to get a count of CVE account for each device.

## Contributing

Expand All @@ -61,7 +110,7 @@ The development environment can be used in 2 ways. First, with a local poetry en
The [PyInvoke](http://www.pyinvoke.org/) library is used to provide some helper commands based on the environment. There are a few configuration parameters which can be passed to PyInvoke to override the default configuration:

* `nautobot_ver`: the version of Nautobot to use as a base for any built docker containers (default: 1.0.1)
* `project_name`: the default docker compose project name (default: nautobot_chatops_extension_arista)
* `project_name`: the default docker compose project name (default: nautobot_plugin_chatops_cloudvision)
* `python_ver`: the version of Python to use as a base for any built docker containers (default: 3.6)
* `local`: a boolean flag indicating if invoke tasks should be run on the host or inside the docker containers (default: False, commands will be run in docker containers)
* `compose_dir`: the full path to a directory containing the project compose files
Expand All @@ -77,7 +126,7 @@ Using PyInvoke these configuration options can be overridden using [several meth

```shell
---
nautobot_chatops_extension_arista:
nautobot_plugin_chatops_cloudvision:
local: true
compose_files:
- "docker-compose.requirements.yml"
Expand All @@ -89,7 +138,7 @@ nautobot_chatops_extension_arista:
poetry shell
poetry install --extras nautobot
export $(cat development/dev.env | xargs)
export $(cat development/creds.env | xargs)
export $(cat development/creds.env | xargs)
invoke start && sleep 5
nautobot-server migrate
```
Expand Down Expand Up @@ -125,7 +174,7 @@ Nautobot server can now be accessed at [http://localhost:8080](http://localhost:

The project is coming with a CLI helper based on [invoke](http://www.pyinvoke.org/) to help setup the development environment. The commands are listed below in 3 categories `dev environment`, `utility` and `testing`.

Each command can be executed with `invoke <command>`. Environment variables `INVOKE_NAUTOBOT_CHATOPS_EXTENSION_ARISTA_PYTHON_VER` and `INVOKE_NAUTOBOT_CHATOPS_EXTENSION_ARISTA_NAUTOBOT_VER` may be specified to override the default versions. Each command also has its own help `invoke <command> --help`
Each command can be executed with `invoke <command>`. Environment variables `INVOKE_NAUTOBOT_CHATOPS_PLUGIN_CLOUDVISION_PYTHON_VER` and `INVOKE_NAUTOBOT_CHATOPS_PLUGIN_CLOUDVISION_NAUTOBOT_VER` may be specified to override the default versions. Each command also has its own help `invoke <command> --help`

#### Docker dev environment

Expand Down Expand Up @@ -159,15 +208,15 @@ Each command can be executed with `invoke <command>`. Environment variables `INV
unittest Run Django unit tests for the plugin.
```

### Project Documentation
## Screenshots

![cloudvision_get_active_events](https://user-images.githubusercontent.com/38091261/128059429-4e4dc269-2113-411b-9721-9ef281a361c5.PNG)
![cloudvision_get_configlet](https://user-images.githubusercontent.com/38091261/128059458-d6395d63-6909-4219-9dcb-dff1801cbda2.PNG)
![cloudvision_get_device_cve](https://user-images.githubusercontent.com/38091261/128059481-2ff60896-81e4-46ae-992b-7d179403fe8f.PNG)


Project documentation is generated by [mkdocs](https://www.mkdocs.org/) from the documentation located in the docs folder. You can configure [readthedocs.io](https://readthedocs.io/) to point at this folder in your repo. For development purposes a `docker-compose.docs.yml` is also included. A container hosting the docs will be started using the invoke commands on [http://localhost:8001](http://localhost:8001), as changes are saved the docs will be automatically reloaded.

## Questions

For any questions or comments, please check the [FAQ](FAQ.md) first and feel free to swing by the [Network to Code slack channel](https://networktocode.slack.com/) (channel #networktocode).
Sign up [here](http://slack.networktocode.com/)

## Screenshots

TODO
2 changes: 1 addition & 1 deletion development/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NAPALM_TIMEOUT=5
NAUTOBOT_ROOT=/opt/nautobot
POSTGRES_DB=nautobot
POSTGRES_HOST=postgres
POSTGRES_USER=nautbot
POSTGRES_USER=nautobot
REDIS_HOST=redis
REDIS_PORT=6379
# REDIS_SSL=True
Expand Down
2 changes: 1 addition & 1 deletion development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def is_truthy(arg):
PAGINATE_COUNT = int(os.environ.get("PAGINATE_COUNT", 50))

# Enable installed plugins. Add the name of each plugin to the list.
PLUGINS = ["nautobot_chatops_extension_arista"]
PLUGINS = ["nautobot_plugin_chatops_cloudvision"]

# Plugins configuration settings. These settings are used by various plugins that the user may have installed.
# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
Expand Down
19 changes: 0 additions & 19 deletions docs/extra.css

This file was deleted.

17 changes: 0 additions & 17 deletions docs/index.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions invoke.example.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
nautobot_chatops_extension_arista:
project_name: "nautobot-chatops-extension-arista"
nautobot_plugin_chatops_cloudvision:
project_name: "nautobot_plugin_chatops_cloudvision"
nautobot_ver: "1.0.1"
local: false
python_ver: "3.6"
Expand Down
1 change: 0 additions & 1 deletion nautobot_chatops_extension_arista/api/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion nautobot_chatops_extension_arista/tests/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions nautobot_chatops_extension_arista/urls.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Plugin declaration for nautobot_chatops_extension_arista."""
"""Plugin declaration for nautobot_plugin_chatops_cloudvision."""

__version__ = "0.1.0"

from nautobot.extras.plugins import PluginConfig


class NautobotChatopsExtensionAristaConfig(PluginConfig):
"""Plugin configuration for the nautobot_chatops_extension_arista plugin."""
"""Plugin configuration for the nautobot_plugin_chatops_cloudvision plugin."""

name = "nautobot_chatops_extension_arista"
verbose_name = "Nautobot Chatops Extension Arista"
name = "nautobot_plugin_chatops_cloudvision"
verbose_name = "Nautobot Plugin Chatops Cloudvision"
version = __version__
author = "Network to Code, LLC"
description = "Nautobot Chatops Extension Arista."
base_url = "nautobot-chatops-extension-arista"
description = "Nautobot Plugin Chatops Cloudvision."
base_url = "nautobot_plugin_chatops_cloudvision"
required_settings = []
min_version = "1.0.0"
max_version = "1.9999"
Expand Down
1 change: 1 addition & 0 deletions nautobot_plugin_chatops_cloudvision/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""REST API module for nautobot_plugin_chatops_cloudvision plugin."""
Loading

0 comments on commit 5dbd35d

Please sign in to comment.