Skip to content

Commit 8c2cb1c

Browse files
authored
feat: NetBox 4.5.x support (#146)
Signed-off-by: Michal Fiedorowicz <mfiedorowicz@netboxlabs.com>
1 parent 82ecf9d commit 8c2cb1c

81 files changed

Lines changed: 1865 additions & 1616 deletions

File tree

Some content is hidden

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

.github/workflows/lint-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
matrix:
2828
python: [ "3.10" ]
29-
netbox: [ "", "v4.2.3" ]
29+
netbox: [ "v4.5.0", "v4.4.10" ]
3030
steps:
3131
- name: Checkout
3232
uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dist/
2828

2929
# Docker
3030
docker/coverage
31-
!docker/netbox/env
31+
!docker/common/netbox/env
3232
!docker/*/netbox/env
3333
docker/oauth2/secrets/*
3434
!docker/oauth2/secrets/.gitkeep

Makefile

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,51 @@ else
44
DOCKER_COMPOSE := docker-compose
55
endif
66

7-
NETBOX_VERSION ?=
8-
ifneq ($(NETBOX_VERSION),)
9-
DOCKER_PATH := docker/$(NETBOX_VERSION)
10-
TEST_SELECTOR := "/opt/netbox/netbox/netbox_diode_plugin/tests/$(NETBOX_VERSION)/tests/"
11-
else
12-
DOCKER_PATH := docker
13-
TEST_SELECTOR = netbox_diode_plugin
14-
endif
7+
# Default to v4.5.x if NETBOX_VERSION is not set
8+
NETBOX_VERSION ?= v4.5.0
9+
# Extract minor version (e.g., v4.5.0 -> v4.5.x)
10+
NETBOX_MINOR_VERSION := $(shell echo $(NETBOX_VERSION) | sed -E 's/^v?([0-9]+\.[0-9]+).*/v\1.x/')
11+
DOCKER_PATH := docker/$(NETBOX_MINOR_VERSION)
12+
DOCKER_COMMON_PATH := docker/common
13+
TEST_SELECTOR := "/opt/netbox/netbox/netbox_diode_plugin/tests/$(NETBOX_MINOR_VERSION)/tests/"
14+
15+
# Export variables so they're available to docker-compose
16+
export NETBOX_VERSION
17+
export NETBOX_MINOR_VERSION
1518

1619
.PHONY: docker-compose-netbox-plugin-up
1720
docker-compose-netbox-plugin-up:
18-
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml up -d --build
21+
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml up -d --build
1922

2023
.PHONY: docker-compose-netbox-plugin-down
2124
docker-compose-netbox-plugin-down:
22-
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml down
25+
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml down
2326

2427
.PHONY: docker-compose-netbox-plugin-test
2528
docker-compose-netbox-plugin-test:
26-
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run -u root --rm netbox ./manage.py test $(TEST_FLAGS) --keepdb $(TEST_SELECTOR); \
29+
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run -u root --rm netbox ./manage.py test $(TEST_FLAGS) --keepdb $(TEST_SELECTOR); \
2730
EXIT_CODE=$$?; \
2831
$(MAKE) docker-compose-netbox-plugin-down; \
2932
exit $$EXIT_CODE
3033

3134
.PHONY: docker-compose-netbox-plugin-test-lint
3235
docker-compose-netbox-plugin-test-lint:
33-
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run -u root --rm netbox ruff check --output-format=github netbox_diode_plugin; \
36+
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run -u root --rm netbox ruff check --output-format=github netbox_diode_plugin; \
3437
EXIT_CODE=$$?; \
3538
$(MAKE) docker-compose-netbox-plugin-down; \
3639
exit $$EXIT_CODE
3740

3841
.PHONY: docker-compose-netbox-plugin-test-cover
3942
docker-compose-netbox-plugin-test-cover:
40-
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/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 $(TEST_SELECTOR) && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"; \
43+
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/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 $(TEST_SELECTOR) && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"; \
4144
EXIT_CODE=$$?; \
4245
$(MAKE) docker-compose-netbox-plugin-down; \
4346
exit $$EXIT_CODE
4447

4548
.PHONY: docker-compose-generate-matching-docs
4649
docker-compose-generate-matching-docs:
47-
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm netbox python manage.py generate_matching_docs | awk '/Generating markdown documentation.../{p=1;next} p' > ./docs/matching-criteria-documentation.md
50+
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run --rm netbox python manage.py generate_matching_docs | awk '/Generating markdown documentation.../{p=1;next} p' > ./docs/matching-criteria-documentation.md
4851

4952
.PHONY: docker-compose-migrate
5053
docker-compose-migrate:
51-
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm netbox python manage.py migrate
54+
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run --rm netbox python manage.py migrate

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ at [https://netboxlabs.com/blog/introducing-diode-streamlining-data-ingestion-in
1212

1313
## Compatibility
1414

15-
| NetBox Version | Plugin Version |
16-
|:--------------:|:--------------:|
17-
| >= 3.7.2 | 0.1.0 |
18-
| >= 4.1.0 | 0.4.0 |
19-
| >= 4.2.3 | 1.0.0 |
20-
| >= 4.2.3 | 1.1.0 |
21-
| >= 4.2.3 | 1.2.0 |
22-
| >= 4.4.0 | 1.4.0 |
23-
| >= 4.4.0 | 1.4.1 |
15+
| NetBox Version | Plugin Version |
16+
|:---------------:|:--------------:|
17+
| >= 3.7.2 | 0.1.0 |
18+
| >= 4.1.0 | 0.4.0 |
19+
| >= 4.2.3 | 1.0.0 |
20+
| >= 4.2.3 | 1.1.0 |
21+
| >= 4.2.3 | 1.2.0 |
22+
| >= 4.4.0 | 1.4.0 |
23+
| >= 4.4.0 | 1.4.1 |
24+
| >= 4.4.10 | 1.7.0 |
25+
| >= 4.5.0 | 1.7.0 |
2426

2527
## Installation
2628

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: diode-netbox-plugin-${NETBOX_MINOR_VERSION:-v4.5.x}
2+
services:
3+
netbox:
4+
volumes:
5+
- ../common/netbox/plugins_test.py:/etc/netbox/config/plugins.py:z,ro
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
name: diode-netbox-plugin-4.2.3
1+
name: diode-netbox-plugin-${NETBOX_MINOR_VERSION:-v4.5.x}
22
services:
33
netbox: &netbox
4-
image: netboxcommunity/netbox:v4.2.3-3.1.1-diode-netbox-plugin
4+
image: netboxcommunity/netbox:${NETBOX_VERSION:-v4.5.0-3.4.2}-diode-netbox-plugin
55
build:
6-
context: .
7-
dockerfile: Dockerfile-diode-netbox-plugin
6+
context: ..
7+
dockerfile: ${NETBOX_MINOR_VERSION:-v4.5.x}/Dockerfile
88
pull: true
9+
args:
10+
NETBOX_VERSION: ${NETBOX_VERSION:-v4.5.0-3.4.2}
911
depends_on:
1012
- netbox-postgres
1113
- netbox-redis
1214
- netbox-redis-cache
13-
env_file: netbox/env/netbox.env
14-
user: 'unit:root'
15+
env_file: ../common/netbox/env/netbox.env
16+
user: "unit:root"
1517
healthcheck:
16-
start_period: 60s
18+
start_period: 180s
1719
timeout: 3s
1820
interval: 15s
1921
test: "curl -f http://localhost:8080/netbox/api/ || exit 1"
@@ -24,15 +26,15 @@ services:
2426
- ../oauth2/secrets:/run/secrets:z,ro
2527
- ./netbox/launch-netbox.sh:/opt/netbox/launch-netbox.sh:z,ro
2628
- ./netbox/plugins_dev.py:/etc/netbox/config/plugins.py:z,ro
27-
- ./coverage:/opt/netbox/netbox/coverage:z,rw
29+
- ../coverage:/opt/netbox/netbox/coverage:z,rw
2830
- netbox-media-files:/opt/netbox/netbox/media:rw
2931
- netbox-reports-files:/opt/netbox/netbox/reports:rw
3032
- netbox-scripts-files:/opt/netbox/netbox/scripts:rw
3133
extra_hosts:
3234
- "host.docker.internal:host-gateway"
3335
ports:
3436
- "8000:8080"
35-
37+
3638
netbox-worker:
3739
<<: *netbox
3840
depends_on:
@@ -48,11 +50,11 @@ services:
4850
timeout: 3s
4951
interval: 15s
5052
ports: []
51-
53+
5254
# postgres
5355
netbox-postgres:
5456
image: docker.io/postgres:16-alpine
55-
env_file: netbox/env/postgres.env
57+
env_file: ../common/netbox/env/postgres.env
5658
volumes:
5759
- netbox-postgres-data:/var/lib/postgresql/data
5860

@@ -63,7 +65,7 @@ services:
6365
- sh
6466
- -c # this is to evaluate the $REDIS_PASSWORD from the env
6567
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
66-
env_file: netbox/env/redis.env
68+
env_file: ../common/netbox/env/redis.env
6769
volumes:
6870
- netbox-redis-data:/data
6971

@@ -73,7 +75,7 @@ services:
7375
- sh
7476
- -c # this is to evaluate the $REDIS_PASSWORD from the env
7577
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
76-
env_file: netbox/env/redis-cache.env
78+
env_file: ../common/netbox/env/redis-cache.env
7779
volumes:
7880
- netbox-redis-cache-data:/data
7981

@@ -89,4 +91,4 @@ volumes:
8991
netbox-reports-files:
9092
driver: local
9193
netbox-scripts-files:
92-
driver: local
94+
driver: local

docker/netbox/configuration/configuration.py renamed to docker/common/netbox/configuration/configuration.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def _read_secret(secret_name: str, default: str | None = None) -> str | None:
3333
# is passed to it as a parameter. The value returned from `map_fn` is then the return value of this function.
3434
# The `map_fn` is not invoked, if the value (that was read from the environment or the default value if not found) is None.
3535
def _environ_get_and_map(
36-
variable_name: str,
37-
default: str | None = None,
38-
map_fn: Callable[[str], Any | None] = None,
36+
variable_name: str,
37+
default: str | None = None,
38+
map_fn: Callable[[str], Any | None] = None,
3939
) -> Any | None:
4040
env_value = environ.get(variable_name, default)
4141

@@ -133,6 +133,12 @@ def _environ_get_and_map(
133133
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY
134134
SECRET_KEY = _read_secret("secret_key", environ.get("SECRET_KEY", ""))
135135

136+
137+
API_TOKEN_PEPPERS = {}
138+
if api_token_pepper := _read_secret('api_token_pepper_1', environ.get('API_TOKEN_PEPPER_1', '')):
139+
API_TOKEN_PEPPERS.update({1: api_token_pepper})
140+
141+
136142
#########################
137143
# #
138144
# Optional settings #
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)