Skip to content

Commit

Permalink
Merge pull request #214 from netbox-community/feat/netbox-4-1
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
cruse1977 authored Oct 10, 2024
2 parents 026c591 + 02f428a commit e262ba8
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARG NETBOX_VARIANT=v4.0
ARG NETBOX_VARIANT=v4.1

FROM netboxcommunity/netbox:${NETBOX_VARIANT}

RUN mkdir -pv /plugins/netbox-acls
COPY . /plugins/netbox-acls

RUN /opt/netbox/venv/bin/python3 /plugins/netbox-acls/setup.py develop && \
cp -rf /plugins/netbox-acls/netbox_acls/ /opt/netbox/venv/lib/python3.11/site-packages/netbox_acls
cp -rf /plugins/netbox-acls/netbox_acls/ /opt/netbox/venv/lib/python3.12/site-packages/netbox_acls
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ See the [CONTRIBUTING](CONTRIBUTING.md) for more information.

Each Plugin Version listed below has been tested with its corresponding NetBox Version.

| NetBox Version | Plugin Version |
| NetBox Version | Plugin Version |
|:-------------------:|:--------------:|
| 4.1.x | 1.7.0 |
| >= 4.0.2 < 4.1.0 | 1.6.1 |
| 3.7 | 1.5.0 |
| 3.6 | 1.4.0 |
| 3.5 | 1.3.0 |
| 3.4 | 1.2.2 |
| 3.3 | 1.1.0 |
| 3.2 | 1.0.1 |
| 3.7.x | 1.5.0 |
| 3.6.x | 1.4.0 |
| 3.5.x | 1.3.0 |
| 3.4.x | 1.2.2 |
| 3.3.x | 1.1.0 |
| 3.2.x | 1.0.1 |

## Installing

Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
version: '3.4'

services:
netbox:
Expand Down
4 changes: 2 additions & 2 deletions netbox_acls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class NetBoxACLsConfig(PluginConfig):
version = __version__
description = "Manage simple ACLs in NetBox"
base_url = "access-lists"
min_version = "4.0.2"
max_version = "4.0.99"
min_version = "4.1.0"
max_version = "4.1.99"


config = NetBoxACLsConfig
20 changes: 10 additions & 10 deletions netbox_acls/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

from django.contrib.contenttypes.models import ContentType
from drf_spectacular.utils import extend_schema_field
from ipam.api.serializers import NestedPrefixSerializer
from ipam.api.serializers import PrefixSerializer
from netbox.api.fields import ContentTypeField
from netbox.api.serializers import NetBoxModelSerializer
from netbox.constants import NESTED_SERIALIZER_PREFIX
from rest_framework import serializers
from utilities.api import get_serializer_for_model

Expand Down Expand Up @@ -81,10 +80,9 @@ class Meta:
def get_assigned_object(self, obj):
serializer = get_serializer_for_model(
obj.assigned_object,
prefix=NESTED_SERIALIZER_PREFIX,
)
context = {"request": self.context["request"]}
return serializer(obj.assigned_object, context=context).data
return serializer(obj.assigned_object, nested=True, context=context).data

def validate(self, data):
"""
Expand Down Expand Up @@ -145,11 +143,10 @@ class Meta:
@extend_schema_field(serializers.DictField())
def get_assigned_object(self, obj):
serializer = get_serializer_for_model(
obj.assigned_object,
prefix=NESTED_SERIALIZER_PREFIX,
obj.assigned_object
)
context = {"request": self.context["request"]}
return serializer(obj.assigned_object, context=context).data
return serializer(obj.assigned_object, nested=True, context=context).data

def validate(self, data):
"""
Expand Down Expand Up @@ -187,10 +184,11 @@ class ACLStandardRuleSerializer(NetBoxModelSerializer):
view_name="plugins-api:netbox_acls-api:aclstandardrule-detail",
)
access_list = NestedAccessListSerializer()
source_prefix = NestedPrefixSerializer(
source_prefix = PrefixSerializer(
required=False,
allow_null=True,
default=None,
nested=True
)

class Meta:
Expand Down Expand Up @@ -251,15 +249,17 @@ class ACLExtendedRuleSerializer(NetBoxModelSerializer):
view_name="plugins-api:netbox_acls-api:aclextendedrule-detail",
)
access_list = NestedAccessListSerializer()
source_prefix = NestedPrefixSerializer(
source_prefix = PrefixSerializer(
required=False,
allow_null=True,
default=None,
nested=True
)
destination_prefix = NestedPrefixSerializer(
destination_prefix = PrefixSerializer(
required=False,
allow_null=True,
default=None,
nested=True
)

class Meta:
Expand Down
40 changes: 10 additions & 30 deletions netbox_acls/forms/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
Defines each django model's GUI filter/search options.
"""

from django.utils.translation import gettext_lazy as _
from dcim.models import Device, Interface, Region, Site, SiteGroup, VirtualChassis
from django import forms
from django.utils.translation import gettext as _
from ipam.models import Prefix
from netbox.forms import NetBoxModelFilterSetForm
from utilities.forms.rendering import FieldSet
from utilities.forms.fields import (
DynamicModelChoiceField,
DynamicModelMultipleChoiceField,
Expand Down Expand Up @@ -90,22 +91,11 @@ class AccessListFilterForm(NetBoxModelFilterSetForm):
tag = TagFilterField(model)

fieldsets = (
(None, ("q", "tag")),
(
"Host Details",
(
"region",
"site_group",
"site",
"device_id",
"virtual_chassis_id",
"virtual_machine_id",
),
),
("ACL Details", ("type", "default_action")),
FieldSet("region", "site_group", "site", "device_id", "virtual_chassis_id", "virtual_machine_id", name=_("Host Details")),
FieldSet("type", "default_action", name=_('ACL Details')),
FieldSet("q", "tag",name=None)
)


class ACLInterfaceAssignmentFilterForm(NetBoxModelFilterSetForm):
"""
GUI filter form to search the django AccessList model.
Expand Down Expand Up @@ -195,12 +185,11 @@ class ACLStandardRuleFilterForm(NetBoxModelFilterSetForm):
choices=add_blank_choice(ACLRuleActionChoices),
required=False,
)

fieldsets = (
(None, ("q", "tag")),
("Rule Details", ("access_list", "action", "source_prefix")),
FieldSet("access_list", "action", "source_prefix", name=_('Rule Details')),
FieldSet("q", "tag",name=None)
)


class ACLExtendedRuleFilterForm(NetBoxModelFilterSetForm):
"""
GUI filter form to search the django ACLExtendedRule model.
Expand Down Expand Up @@ -235,15 +224,6 @@ class ACLExtendedRuleFilterForm(NetBoxModelFilterSetForm):
)

fieldsets = (
(None, ("q", "tag")),
(
"Rule Details",
(
"access_list",
"action",
"source_prefix",
"desintation_prefix",
"protocol",
),
),
FieldSet("access_list", "action", "source_prefix", "desintation_prefix", "protocol", name=_('Rule Details')),
FieldSet("q", "tag",name=None)
)
44 changes: 24 additions & 20 deletions netbox_acls/forms/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
Defines each django model's GUI form to add or edit objects for each django model.
"""

from django.utils.translation import gettext_lazy as _
from dcim.models import Device, Interface, Region, Site, SiteGroup, VirtualChassis
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.utils.safestring import mark_safe
from ipam.models import Prefix
from netbox.forms import NetBoxModelForm
from utilities.forms.rendering import FieldSet
from utilities.forms.fields import CommentField, DynamicModelChoiceField
from virtualization.models import (
Cluster,
Expand Down Expand Up @@ -118,7 +119,12 @@ class AccessListForm(NetBoxModelForm):
)

comments = CommentField()

fieldsets = (
FieldSet('region', 'site_group', 'site', 'virtual_machine', 'virtual_chassis', 'device', name=_('Assignment')),
FieldSet('name', 'type', 'default_action', name=_('Access List')),
FieldSet('comments', 'tags', name=_('')),
)

class Meta:
model = AccessList
fields = (
Expand All @@ -134,6 +140,7 @@ class Meta:
"comments",
"tags",
)

help_texts = {
"default_action": "The default behavior of the ACL.",
"name": "The name uniqueness per device is case insensitive.",
Expand Down Expand Up @@ -285,6 +292,11 @@ class ACLInterfaceAssignmentForm(NetBoxModelForm):
),
)
comments = CommentField()
fieldsets = (
FieldSet('device', 'interface', 'virtual_machine', 'vminterface', name=_('Assignment')),
FieldSet('access_list', 'direction', name=_('Access List Details')),
FieldSet('comments', 'tags', name=_('')),
)

def __init__(self, *args, **kwargs):
# Initialize helper selectors
Expand Down Expand Up @@ -313,6 +325,7 @@ class Meta:
"comments",
"tags",
)

help_texts = {
"direction": mark_safe(
"<b>*Note:</b> CANNOT assign 2 ACLs to the same interface & direction.",
Expand Down Expand Up @@ -440,10 +453,9 @@ class ACLStandardRuleForm(NetBoxModelForm):
)

fieldsets = (
("Access List Details", ("access_list", "description", "tags")),
("Rule Definition", ("index", "action", "remark", "source_prefix")),
FieldSet("access_list", "description", "tags", name=_('Access List Details')),
FieldSet("index", "action", "remark", "source_prefix", name=_('Rule Definition'))
)

class Meta:
model = ACLStandardRule
fields = (
Expand All @@ -455,6 +467,10 @@ class Meta:
"tags",
"description",
)




help_texts = {
"index": help_text_acl_rule_index,
"action": help_text_acl_action,
Expand Down Expand Up @@ -524,22 +540,9 @@ class ACLExtendedRuleForm(NetBoxModelForm):
label="Destination Prefix",
)
fieldsets = (
("Access List Details", ("access_list", "description", "tags")),
(
"Rule Definition",
(
"index",
"action",
"remark",
"source_prefix",
"source_ports",
"destination_prefix",
"destination_ports",
"protocol",
),
),
FieldSet("access_list", "description", "tags", name=_('Access List Details')),
FieldSet("index", "action", "remark", "source_prefix", "source_ports", "destination_prefix", "destination_ports", "protocol", name=_('Rule Definition'))
)

class Meta:
model = ACLExtendedRule
fields = (
Expand All @@ -555,6 +558,7 @@ class Meta:
"tags",
"description",
)

help_texts = {
"action": help_text_acl_action,
"destination_ports": help_text_acl_rule_logic,
Expand Down
2 changes: 1 addition & 1 deletion netbox_acls/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.6.1"
__version__ = "1.7.0"
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_version(relative_path):
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Intended Audience :: System Administrators",
"Intended Audience :: Telecommunications Industry",
"Framework :: Django",
Expand Down

0 comments on commit e262ba8

Please sign in to comment.