From b7002881104f371ecc9e63fd5e4afb407e8e02fb Mon Sep 17 00:00:00 2001 From: Michal Fiedorowicz Date: Tue, 3 Sep 2024 22:29:40 +0100 Subject: [PATCH] feat: NetBox 4.1 support (#21) Signed-off-by: Michal Fiedorowicz --- README.md | 11 +++++++---- docker/Dockerfile-diode-netbox-plugin | 2 +- docker/docker-compose.yaml | 2 +- netbox_diode_plugin/api/serializers.py | 12 +++++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7793a0a..1506ec5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Diode NetBox Plugin -The Diode NetBox plugin is a [NetBox](https://netboxlabs.com/oss/netbox/) plugin. It is a required component of the [Diode](https://github.com/netboxlabs/diode) ingestion service. +The Diode NetBox plugin is a [NetBox](https://netboxlabs.com/oss/netbox/) plugin. It is a required component of +the [Diode](https://github.com/netboxlabs/diode) ingestion service. Diode is a NetBox ingestion service that greatly simplifies and enhances the process to add and update network data in NetBox, ensuring your network source of truth is always accurate and can be trusted to power your network automation @@ -12,8 +13,9 @@ at [https://netboxlabs.com/blog/introducing-diode-streamlining-data-ingestion-in ## Compatibility | NetBox Version | Plugin Version | -|----------------|----------------| -| >= 3.7.2 | 0.1.0 | +|:--------------:|:--------------:| +| >= 3.7.2 | 0.1.0 | +| >= 4.1.0 | 0.3.0 | ## Installation @@ -55,7 +57,8 @@ cd /opt/netbox source venv/bin/activate ``` -Three API keys will be needed (these are random 40 character long alphanumeric strings). They can be generated and set to the appropriate environment variables with the following commands: +Three API keys will be needed (these are random 40 character long alphanumeric strings). They can be generated and set +to the appropriate environment variables with the following commands: ```shell # API key for the Diode service to interact with NetBox diff --git a/docker/Dockerfile-diode-netbox-plugin b/docker/Dockerfile-diode-netbox-plugin index 3358b6d..395ac08 100644 --- a/docker/Dockerfile-diode-netbox-plugin +++ b/docker/Dockerfile-diode-netbox-plugin @@ -1,4 +1,4 @@ -FROM netboxcommunity/netbox:v4.0-2.9.1 +FROM netboxcommunity/netbox:v4.1-beta1-2.9.1 COPY ./netbox/configuration/ /etc/netbox/config/ RUN chmod 755 /etc/netbox/config/* && \ diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 751df56..ebb6c73 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,7 +1,7 @@ name: diode-netbox-plugin services: netbox: &netbox - image: netboxcommunity/netbox:v4.0-2.9.1-diode-netbox-plugin + image: netboxcommunity/netbox:v4.1-beta1-2.9.1-diode-netbox-plugin build: context: . dockerfile: Dockerfile-diode-netbox-plugin diff --git a/netbox_diode_plugin/api/serializers.py b/netbox_diode_plugin/api/serializers.py index f570884..e33ef07 100644 --- a/netbox_diode_plugin/api/serializers.py +++ b/netbox_diode_plugin/api/serializers.py @@ -13,8 +13,13 @@ PlatformSerializer, SiteSerializer, ) -from django.core.exceptions import FieldDoesNotExist -from extras.models import ObjectChange +from django.conf import settings +from packaging import version + +if version.parse(version.parse(settings.VERSION).base_version) >= version.parse("4.1"): + from core.models import ObjectChange +else: + from extras.models import ObjectChange from ipam.api.serializers import IPAddressSerializer, PrefixSerializer from rest_framework import serializers from rest_framework.utils.serializer_helpers import ReturnDict @@ -23,9 +28,9 @@ ClusterGroupSerializer, ClusterSerializer, ClusterTypeSerializer, - VMInterfaceSerializer, VirtualDiskSerializer, VirtualMachineSerializer, + VMInterfaceSerializer, ) logger = logging.getLogger("netbox.netbox_diode_plugin.api.serializers") @@ -329,6 +334,7 @@ class Meta: model = VirtualDiskSerializer.Meta.model fields = VirtualDiskSerializer.Meta.fields + class DiodeVMInterfaceSerializer(VMInterfaceSerializer): """Diode VM Interface Serializer."""