Skip to content

Commit 28672d5

Browse files
authored
feat: diode data plugin 1.0 rc (#88)
2 parents 53fbc02 + ece4fe8 commit 28672d5

File tree

83 files changed

+12517
-5548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+12517
-5548
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @leoparente @mfiedorowicz
1+
* @leoparente @ltucker @mfiedorowicz

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ docker-compose-netbox-plugin-down:
1414

1515
.PHONY: docker-compose-netbox-plugin-test
1616
docker-compose-netbox-plugin-test:
17-
-@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run -u root --rm netbox ./manage.py test --keepdb netbox_diode_plugin
17+
-@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run -u root --rm netbox ./manage.py test $(TEST_FLAGS) --keepdb netbox_diode_plugin
1818
@$(MAKE) docker-compose-netbox-plugin-down
1919

2020
.PHONY: docker-compose-netbox-plugin-test-cover
2121
docker-compose-netbox-plugin-test-cover:
22-
-@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run --rm -u root -e COVERAGE_FILE=/opt/netbox/netbox/coverage/.coverage netbox sh -c "coverage run --source=netbox_diode_plugin --omit=*_pb2*,*/migrations/* ./manage.py test --keepdb netbox_diode_plugin && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"
22+
-@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run --rm -u root -e COVERAGE_FILE=/opt/netbox/netbox/coverage/.coverage netbox sh -c "coverage run --source=netbox_diode_plugin --omit=*/migrations/* ./manage.py test --keepdb netbox_diode_plugin && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"
2323
@$(MAKE) docker-compose-netbox-plugin-down

README.md

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ at [https://netboxlabs.com/blog/introducing-diode-streamlining-data-ingestion-in
1616
|:--------------:|:--------------:|
1717
| >= 3.7.2 | 0.1.0 |
1818
| >= 4.1.0 | 0.4.0 |
19+
| >= 4.2.3 | 1.0.0 |
1920

2021
## Installation
2122

@@ -46,32 +47,18 @@ Also in your `configuration.py` file, in order to customise the plugin settings,
4647
```python
4748
PLUGINS_CONFIG = {
4849
"netbox_diode_plugin": {
49-
# Auto-provision users for Diode plugin
50-
"auto_provision_users": False,
51-
5250
# Diode gRPC target for communication with Diode server
5351
"diode_target_override": "grpc://localhost:8080/diode",
5452

55-
# User allowed for Diode to NetBox communication
56-
"diode_to_netbox_username": "diode-to-netbox",
57-
58-
# User allowed for NetBox to Diode communication
59-
"netbox_to_diode_username": "netbox-to-diode",
60-
61-
# User allowed for data ingestion
62-
"diode_username": "diode-ingestion",
53+
# Username associated with changes applied via plugin
54+
"diode_username": "diode",
6355
},
6456
}
6557
```
6658

6759
Note: Once you customise usernames with PLUGINS_CONFIG during first installation, you should not change or remove them
6860
later on. Doing so will cause the plugin to stop working properly.
6961

70-
`auto_provision_users` is a boolean flag (default: `False`) that determines whether the plugin should automatically
71-
create the users during
72-
migration. If set to `False`, you will need to provision Diode users with their API keys manually via the plugin's setup
73-
page in the NetBox UI.
74-
7562
Restart NetBox services to load the plugin:
7663

7764
```
@@ -89,28 +76,6 @@ cd /opt/netbox
8976
source venv/bin/activate
9077
```
9178

92-
Three API keys will be needed (these are random 40 character long alphanumeric strings). They can be generated and set
93-
to the appropriate environment variables with the following commands:
94-
95-
```shell
96-
# API key for the Diode service to interact with NetBox
97-
export DIODE_TO_NETBOX_API_KEY=$(head -c20 </dev/urandom|xxd -p); env | grep DIODE_TO_NETBOX_API_KEY
98-
# API key for the NetBox service to interact with Diode
99-
export NETBOX_TO_DIODE_API_KEY=$(head -c20 </dev/urandom|xxd -p); env | grep NETBOX_TO_DIODE_API_KEY
100-
# API key for Diode SDKs to ingest data into Diode
101-
export DIODE_API_KEY=$(head -c20 </dev/urandom|xxd -p); env | grep DIODE_API_KEY
102-
```
103-
104-
**Note:** store these API key strings in a safe place as they will be needed later to configure the Diode server.
105-
106-
If you don't set these environment variables, the plugin will generate random API keys for you either during the
107-
migration process (with `auto_provision_users` set to `True`) or when you manually create the users in the plugin's
108-
setup page in the NetBox UI.
109-
110-
It's important to note that environment variables with API keys should be populated in the Diode server's
111-
environment variables (see [docs](https://github.com/netboxlabs/diode/tree/develop/diode-server#running-the-diode-server))
112-
as well to ensure proper communication between the Diode SDK, Diode server and the NetBox plugin.
113-
11479
Run migrations to create all necessary resources:
11580

11681
```shell
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
FROM netboxcommunity/netbox:v4.1-3.0.1
1+
FROM netboxcommunity/netbox:v4.2.3-3.1.1
22

33
COPY ./netbox/configuration/ /etc/netbox/config/
44
RUN chmod 755 /etc/netbox/config/* && \
55
chown unit:root /etc/netbox/config/*
66

7+
COPY ./netbox/local_settings.py /opt/netbox/netbox/netbox/local_settings.py
8+
RUN chmod 755 /opt/netbox/netbox/netbox/local_settings.py && \
9+
chown unit:root /opt/netbox/netbox/netbox/local_settings.py
10+
711
COPY ./requirements-diode-netbox-plugin.txt /opt/netbox/
812
RUN /opt/netbox/venv/bin/pip install --no-warn-script-location -r /opt/netbox/requirements-diode-netbox-plugin.txt

docker/docker-compose.yaml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: diode-netbox-plugin
22
services:
3-
netbox:
4-
image: netboxcommunity/netbox:v4.1-3.0.1-diode-netbox-plugin
3+
netbox: &netbox
4+
image: netboxcommunity/netbox:v4.2.3-3.1.1-diode-netbox-plugin
55
build:
66
context: .
77
dockerfile: Dockerfile-diode-netbox-plugin
@@ -22,13 +22,30 @@ services:
2222
- ./netbox/nginx-unit.json:/opt/netbox/nginx-unit.json:z,ro
2323
- ../netbox_diode_plugin:/opt/netbox/netbox/netbox_diode_plugin:ro
2424
- ./netbox/launch-netbox.sh:/opt/netbox/launch-netbox.sh:z,ro
25+
- ./netbox/plugins_dev.py:/etc/netbox/config/plugins.py:z,ro
2526
- ./coverage:/opt/netbox/netbox/coverage:z,rw
2627
- netbox-media-files:/opt/netbox/netbox/media:rw
2728
- netbox-reports-files:/opt/netbox/netbox/reports:rw
2829
- netbox-scripts-files:/opt/netbox/netbox/scripts:rw
2930
ports:
3031
- "8000:8080"
31-
32+
33+
netbox-worker:
34+
<<: *netbox
35+
depends_on:
36+
netbox:
37+
condition: service_healthy
38+
command:
39+
- /opt/netbox/venv/bin/python
40+
- /opt/netbox/netbox/manage.py
41+
- rqworker
42+
healthcheck:
43+
test: ps -aux | grep -v grep | grep -q rqworker || exit 1
44+
start_period: 20s
45+
timeout: 3s
46+
interval: 15s
47+
ports: []
48+
3249
# postgres
3350
netbox-postgres:
3451
image: docker.io/postgres:16-alpine

docker/netbox/configuration/configuration.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ def _environ_get_and_map(variable_name: str, default: str | None = None,
4444
return map_fn(env_value)
4545

4646

47-
_AS_BOOL = lambda value: value.lower() == 'true'
48-
_AS_INT = lambda value: int(value)
49-
_AS_LIST = lambda value: list(filter(None, value.split(' ')))
47+
def _AS_BOOL(value):
48+
return value.lower() == 'true'
49+
def _AS_INT(value):
50+
return int(value)
51+
def _AS_LIST(value):
52+
return list(filter(None, value.split(' ')))
5053

5154
_BASE_DIR = dirname(dirname(abspath(__file__)))
5255

docker/netbox/configuration/logging.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
from os import environ
2+
3+
LOGGING = {
4+
'version': 1,
5+
'disable_existing_loggers': False,
6+
'handlers': {
7+
'console': {
8+
'class': 'logging.StreamHandler',
9+
},
10+
},
11+
'loggers': {
12+
'': { # root logger
13+
'handlers': ['console'],
14+
'level': 'DEBUG' if environ.get('DEBUG', 'false').lower() == 'true' else 'INFO',
15+
},
16+
},
17+
}
118
# # Remove first comment(#) on each line to implement this working logging example.
219
# # Add LOGLEVEL environment variable to netbox if you use this example & want a different log level.
320
# from os import environ

docker/netbox/configuration/plugins.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
# To learn how to build images with your required plugins
55
# See https://github.com/netbox-community/netbox-docker/wiki/Using-Netbox-Plugins
66

7-
PLUGINS = ["netbox_diode_plugin"]
7+
PLUGINS = [
8+
"netbox_diode_plugin",
9+
"netbox_branching",
10+
]
811

912
# PLUGINS_CONFIG = {
1013
# "netbox_diode_plugin": {

docker/netbox/env/netbox.env

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,5 @@ SUPERUSER_NAME=admin
3737
SUPERUSER_PASSWORD=admin
3838
WEBHOOKS_ENABLED=true
3939
RELOAD_NETBOX_ON_DIODE_PLUGIN_CHANGE=false
40-
DIODE_TO_NETBOX_API_KEY=1368dbad13e418d5a443d93cf255edde03a2a754
41-
NETBOX_TO_DIODE_API_KEY=1e99338b8cab5fc637bc55f390bda1446f619c42
42-
DIODE_API_KEY=5a52c45ee8231156cb620d193b0291912dd15433
4340
BASE_PATH=netbox/
41+
DEBUG=False

docker/netbox/local_settings.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from netbox_branching.utilities import DynamicSchemaDict
2+
3+
from .configuration import DATABASE
4+
5+
# Wrap DATABASES with DynamicSchemaDict for dynamic schema support
6+
DATABASES = DynamicSchemaDict({
7+
'default': DATABASE,
8+
})
9+
10+
# Employ our custom database router
11+
DATABASE_ROUTERS = [
12+
'netbox_branching.database.BranchAwareRouter',
13+
]

0 commit comments

Comments
 (0)