Skip to content

Commit

Permalink
fixes from issues #1, #2, #3, #4
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson committed Mar 23, 2023
1 parent 3308cac commit c395860
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 39 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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:
Expand Down
14 changes: 12 additions & 2 deletions netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand All @@ -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),
]

0 comments on commit c395860

Please sign in to comment.