From c395860fbf516ac3cfc7657b6657517d5af24f22 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 23 Mar 2023 10:20:58 -0700 Subject: [PATCH] fixes from issues #1, #2, #3, #4 --- MANIFEST.in | 1 + README.md | 45 ++++++++++++++++--- .../migrations/0002_auto_20230215_1752.py | 14 +++++- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index ca948a2..b3b0a4a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,5 +5,6 @@ include README.md recursive-include tests * recursive-exclude * __pycache__ recursive-exclude * *.py[co] +recursive-include netbox_napalm_plugin/templates * recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif diff --git a/README.md b/README.md index 198b7ab..53c0d11 100644 --- a/README.md +++ b/README.md @@ -19,31 +19,38 @@ The features the plugin provides should be listed here. |----------------|----------------| | 3.5 | 0.1.0 | -## Installing +### Installation For adding to a NetBox Docker setup see [the general instructions for using netbox-docker with plugins](https://github.com/netbox-community/netbox-docker/wiki/Using-Netbox-Plugins). While this is still in development and not yet on pypi you can install with pip: -```bash -pip install git+https://github.com/netbox-community/netbox-napalm +```no-highlight +$ source /opt/netbox/venv/bin/activate +(venv) pip install git+https://github.com/netbox-community/netbox-napalm ``` or by adding to your `local_requirements.txt` or `plugin_requirements.txt` (netbox-docker): -```bash -git+https://github.com/netbox-community/netbox-napalm +```no-highlight +(venv) git+https://github.com/netbox-community/netbox-napalm ``` +### Enable the Plugin + Enable the plugin in `/opt/netbox/netbox/netbox/configuration.py`, or if you use netbox-docker, your `/configuration/plugins.py` file : ```python PLUGINS = [ - 'Napalm' + 'netbox_napalm_plugin' ] +### Configure Plugin + +Configure the plugin in `configuration.py` under the `PLUGINS_CONFIG` parameter. + PLUGINS_CONFIG = { 'netbox_napalm_plugin': { 'NAPALM_USERNAME': 'xxx', @@ -52,6 +59,32 @@ PLUGINS_CONFIG = { } ``` +### Run Database Migrations + +Run the provided schema migrations: + +```no-highlight +(venv) $ cd /opt/netbox/netbox/ +(venv) $ python3 manage.py migrate +``` + +### Collect Static Files + +Ensure the static files are copied to the static root directory with the `collectstatic` management command: + +```no-highlight +(venv) $ cd /opt/netbox/netbox/ +(venv) $ python3 manage.py collectstatic +``` + +### Restart WSGI Service + +Restart the WSGI service to load the new plugin: + +```no-highlight +# sudo systemctl restart netbox +``` + ## Credits Based on the NetBox plugin tutorial: diff --git a/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py b/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py index 7ae5a48..64f0cee 100644 --- a/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py +++ b/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py @@ -3,7 +3,7 @@ from django.db import migrations -def migrate_napalm(apps, schema_editor): +def forwards_migrate_napalm(apps, schema_editor): Platform = apps.get_model("dcim", "Platform") NapalmPlatformConfig = apps.get_model("netbox_napalm_plugin", "NapalmPlatformConfig") qs = Platform.objects.all().exclude(napalm_driver__exact="") @@ -15,11 +15,21 @@ def migrate_napalm(apps, schema_editor): ) +def reverse_migrate_napalm(apps, schema_editor): + Platform = apps.get_model("dcim", "Platform") + NapalmPlatformConfig = apps.get_model("netbox_napalm_plugin", "NapalmPlatformConfig") + qs = Platform.objects.all().exclude(napalm_driver__exact="") + for platform in qs: + NapalmPlatformConfig.objects.delete( + platform=platform, + ) + + class Migration(migrations.Migration): dependencies = [ ("netbox_napalm_plugin", "0001_initial"), ] operations = [ - migrations.RunPython(migrate_napalm), + migrations.RunPython(forwards_migrate_napalm, reverse_migrate_napalm), ]