From 3480a885351257e5305006d9eeee0b7b63984c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AE=D0=B7=D0=B5=D1=84=D0=BE=D0=B2=D0=B8=D1=87=20=D0=9D?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=98=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B5=D0=B2=D0=B8=D1=87?= Date: Wed, 14 Sep 2022 10:25:30 +0500 Subject: [PATCH] add communitystatuschoices; --- Makefile | 2 +- README.md | 6 ++---- netbox_bgp/__init__.py | 1 - netbox_bgp/api/serializers.py | 13 +++++++------ netbox_bgp/choices.py | 13 +++++++++++++ netbox_bgp/forms.py | 13 ++++++------- netbox_bgp/models.py | 15 +++++---------- netbox_bgp/version.py | 2 +- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index e1aae91..0b22891 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PYTHON_VER?=3.8 -NETBOX_VER?=v3.2.9 +NETBOX_VER?=v3.2.4 NAME=netbox-bgp diff --git a/README.md b/README.md index ca943ef..0d5f1aa 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ ## Features This plugin provide following Models: -* AS Numbers (will be removed in 0.8.0) * BGP Communities * BGP Sessions * Routing Policy @@ -17,7 +16,7 @@ This plugin provide following Models: | NetBox 2.11 | 0.3.9 | | NetBox 3.0 | 0.4.3 | | NetBox 3.1 | 0.5.0 | -| NetBox 3.2 | 0.6.0 | +| NetBox 3.2 | >= 0.6.0 | ## Installation @@ -36,8 +35,7 @@ Restart NetBox and add `netbox-bgp` to your local_requirements.txt The following options are available: * `device_ext_page`: String (default right) Device related BGP sessions table position. The following values are available: -left, right, full_width. Set empty value for disable. -* `asdot`: Boolean (defaul False) asdot notation for 4-byte AS +left, right, full_width. Set empty value for disable. ## Screenshots diff --git a/netbox_bgp/__init__.py b/netbox_bgp/__init__.py index 7cf922c..847c1f5 100644 --- a/netbox_bgp/__init__.py +++ b/netbox_bgp/__init__.py @@ -15,7 +15,6 @@ class BGPConfig(PluginConfig): max_version = '3.2.99' default_settings = { 'device_ext_page': 'right', - 'asdot': False } diff --git a/netbox_bgp/api/serializers.py b/netbox_bgp/api/serializers.py index 676bf5d..f278349 100644 --- a/netbox_bgp/api/serializers.py +++ b/netbox_bgp/api/serializers.py @@ -1,19 +1,20 @@ -from rest_framework.serializers import Serializer, HyperlinkedIdentityField, ValidationError +from rest_framework.serializers import HyperlinkedIdentityField, ValidationError from rest_framework.relations import PrimaryKeyRelatedField -from netbox.api import ChoiceField, WritableNestedSerializer, ValidatedModelSerializer +from netbox.api import ChoiceField, WritableNestedSerializer from netbox.api.serializers import NetBoxModelSerializer from dcim.api.nested_serializers import NestedSiteSerializer, NestedDeviceSerializer from tenancy.api.nested_serializers import NestedTenantSerializer -from extras.api.nested_serializers import NestedTagSerializer from ipam.api.nested_serializers import NestedIPAddressSerializer, NestedASNSerializer from netbox_bgp.models import ( - BGPSession, SessionStatusChoices, RoutingPolicy, BGPPeerGroup, - Community, RoutingPolicyRule, PrefixList, PrefixListRule + BGPSession, RoutingPolicy, BGPPeerGroup, + Community, RoutingPolicyRule, PrefixList, PrefixListRule, ) +from netbox_bgp.choices import CommunityStatusChoices, SessionStatusChoices + class SerializedPKRelatedField(PrimaryKeyRelatedField): def __init__(self, serializer, **kwargs): @@ -139,7 +140,7 @@ class Meta: class CommunitySerializer(NetBoxModelSerializer): - status = ChoiceField(choices=SessionStatusChoices, required=False) + status = ChoiceField(choices=CommunityStatusChoices, required=False) tenant = NestedTenantSerializer(required=False, allow_null=True) class Meta: diff --git a/netbox_bgp/choices.py b/netbox_bgp/choices.py index d7cbe34..b36db52 100644 --- a/netbox_bgp/choices.py +++ b/netbox_bgp/choices.py @@ -1,6 +1,19 @@ from utilities.choices import ChoiceSet +class CommunityStatusChoices(ChoiceSet): + + STATUS_ACTIVE = 'active' + STATUS_RESERVED = 'reserved' + STATUS_DEPRECATED = 'deprecated' + + CHOICES = ( + (STATUS_ACTIVE, 'Active', 'blue'), + (STATUS_RESERVED, 'Reserved', 'cyan'), + (STATUS_DEPRECATED, 'Deprecated', 'red'), + ) + + class SessionStatusChoices(ChoiceSet): STATUS_OFFLINE = 'offline' diff --git a/netbox_bgp/forms.py b/netbox_bgp/forms.py index 959c445..a17d736 100644 --- a/netbox_bgp/forms.py +++ b/netbox_bgp/forms.py @@ -18,12 +18,11 @@ from netbox.forms import NetBoxModelForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm from .models import ( - Community, BGPSession, SessionStatusChoices, - RoutingPolicy, BGPPeerGroup, RoutingPolicyRule, PrefixList, PrefixListRule + Community, BGPSession, RoutingPolicy, BGPPeerGroup, + RoutingPolicyRule, PrefixList, PrefixListRule ) - -from django.forms.widgets import TextInput +from .choices import SessionStatusChoices, CommunityStatusChoices class CommunityForm(NetBoxModelForm): @@ -33,7 +32,7 @@ class CommunityForm(NetBoxModelForm): ) status = forms.ChoiceField( required=False, - choices=SessionStatusChoices, + choices=CommunityStatusChoices, widget=StaticSelect() ) tenant = DynamicModelChoiceField( @@ -58,7 +57,7 @@ class CommunityFilterForm(NetBoxModelFilterSetForm): required=False ) status = forms.MultipleChoiceField( - choices=SessionStatusChoices, + choices=CommunityStatusChoices, required=False, widget=StaticSelectMultiple() ) @@ -87,7 +86,7 @@ class CommunityBulkEditForm(NetBoxModelBulkEditForm): ) status = forms.ChoiceField( required=False, - choices=SessionStatusChoices, + choices=CommunityStatusChoices, widget=StaticSelect() ) diff --git a/netbox_bgp/models.py b/netbox_bgp/models.py index 14f841e..96716be 100644 --- a/netbox_bgp/models.py +++ b/netbox_bgp/models.py @@ -1,17 +1,12 @@ from django.urls import reverse from django.db import models from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator -from django.core.exceptions import FieldError, ValidationError -from django.conf import settings - -from taggit.managers import TaggableManager +from django.core.exceptions import ValidationError from netbox.models import NetBoxModel -from netbox.models.features import ChangeLoggingMixin from ipam.fields import IPNetworkField -from ipam.models import Prefix -from .choices import IPAddressFamilyChoices, SessionStatusChoices, ActionChoices +from .choices import IPAddressFamilyChoices, SessionStatusChoices, ActionChoices, CommunityStatusChoices class RoutingPolicy(NetBoxModel): @@ -86,8 +81,8 @@ class BGPBase(NetBoxModel): ) status = models.CharField( max_length=50, - choices=SessionStatusChoices, - default=SessionStatusChoices.STATUS_ACTIVE + choices=CommunityStatusChoices, + default=CommunityStatusChoices.STATUS_ACTIVE ) role = models.ForeignKey( to='ipam.Role', @@ -119,7 +114,7 @@ def __str__(self): return self.value def get_status_color(self): - return SessionStatusChoices.colors.get(self.status) + return CommunityStatusChoices.colors.get(self.status) def get_absolute_url(self): return reverse('plugins:netbox_bgp:community', args=[self.pk]) diff --git a/netbox_bgp/version.py b/netbox_bgp/version.py index 49e0fc1..777f190 100644 --- a/netbox_bgp/version.py +++ b/netbox_bgp/version.py @@ -1 +1 @@ -__version__ = "0.7.0" +__version__ = "0.8.0"