Skip to content

Commit

Permalink
Merge pull request #22 from netboxlabs/develop
Browse files Browse the repository at this point in the history
🚚 release: v0.3.0
  • Loading branch information
mfiedorowicz authored Sep 3, 2024
2 parents e60458e + b700288 commit 2a474d7
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 10 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-diode-netbox-plugin
Original file line number Diff line number Diff line change
@@ -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/* && \
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
99 changes: 95 additions & 4 deletions netbox_diode_plugin/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# Copyright 2024 NetBox Labs Inc
"""Diode NetBox Plugin - Serializers."""

import copy
import logging
from collections import OrderedDict

from dcim.api.serializers import (
DeviceRoleSerializer,
Expand All @@ -15,12 +13,25 @@
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
from utilities.api import get_serializer_for_model
from virtualization.api.serializers import (
ClusterGroupSerializer,
ClusterSerializer,
ClusterTypeSerializer,
VirtualDiskSerializer,
VirtualMachineSerializer,
VMInterfaceSerializer,
)

logger = logging.getLogger("netbox.netbox_diode_plugin.api.serializers")

Expand Down Expand Up @@ -254,3 +265,83 @@ class Meta:

model = PrefixSerializer.Meta.model
fields = PrefixSerializer.Meta.fields


class DiodeClusterGroupSerializer(ClusterGroupSerializer):
"""Diode Cluster Group Serializer."""

class Meta:
"""Meta class."""

model = ClusterGroupSerializer.Meta.model
fields = ClusterGroupSerializer.Meta.fields


class DiodeClusterTypeSerializer(ClusterTypeSerializer):
"""Diode Cluster Type Serializer."""

class Meta:
"""Meta class."""

model = ClusterTypeSerializer.Meta.model
fields = ClusterTypeSerializer.Meta.fields


class DiodeClusterSerializer(ClusterSerializer):
"""Diode Cluster Serializer."""

type = DiodeClusterTypeSerializer()
group = DiodeClusterGroupSerializer()
status = serializers.CharField()
site = DiodeSiteSerializer()

class Meta:
"""Meta class."""

model = ClusterSerializer.Meta.model
fields = ClusterSerializer.Meta.fields


class DiodeVirtualMachineSerializer(VirtualMachineSerializer):
"""Diode Virtual Machine Serializer."""

status = serializers.CharField()
site = DiodeSiteSerializer()
cluster = DiodeClusterSerializer()
device = DiodeDeviceSerializer()
role = DiodeDeviceRoleSerializer()
tenant = serializers.CharField()
platform = DiodePlatformSerializer()
primary_ip = DiodeIPAddressSerializer()
primary_ip4 = DiodeIPAddressSerializer()
primary_ip6 = DiodeIPAddressSerializer()

class Meta:
"""Meta class."""

model = VirtualMachineSerializer.Meta.model
fields = VirtualMachineSerializer.Meta.fields


class DiodeVirtualDiskSerializer(VirtualDiskSerializer):
"""Diode Virtual Disk Serializer."""

virtual_machine = DiodeVirtualMachineSerializer()

class Meta:
"""Meta class."""

model = VirtualDiskSerializer.Meta.model
fields = VirtualDiskSerializer.Meta.fields


class DiodeVMInterfaceSerializer(VMInterfaceSerializer):
"""Diode VM Interface Serializer."""

virtual_machine = DiodeVirtualMachineSerializer()

class Meta:
"""Meta class."""

model = VMInterfaceSerializer.Meta.model
fields = VMInterfaceSerializer.Meta.fields

0 comments on commit 2a474d7

Please sign in to comment.