Skip to content

Commit

Permalink
add communitystatuschoices;
Browse files Browse the repository at this point in the history
  • Loading branch information
k01ek committed Sep 14, 2022
1 parent 855ecde commit 3480a88
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PYTHON_VER?=3.8
NETBOX_VER?=v3.2.9
NETBOX_VER?=v3.2.4

NAME=netbox-bgp

Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion netbox_bgp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class BGPConfig(PluginConfig):
max_version = '3.2.99'
default_settings = {
'device_ext_page': 'right',
'asdot': False
}


Expand Down
13 changes: 7 additions & 6 deletions netbox_bgp/api/serializers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions netbox_bgp/choices.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
13 changes: 6 additions & 7 deletions netbox_bgp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -33,7 +32,7 @@ class CommunityForm(NetBoxModelForm):
)
status = forms.ChoiceField(
required=False,
choices=SessionStatusChoices,
choices=CommunityStatusChoices,
widget=StaticSelect()
)
tenant = DynamicModelChoiceField(
Expand All @@ -58,7 +57,7 @@ class CommunityFilterForm(NetBoxModelFilterSetForm):
required=False
)
status = forms.MultipleChoiceField(
choices=SessionStatusChoices,
choices=CommunityStatusChoices,
required=False,
widget=StaticSelectMultiple()
)
Expand Down Expand Up @@ -87,7 +86,7 @@ class CommunityBulkEditForm(NetBoxModelBulkEditForm):
)
status = forms.ChoiceField(
required=False,
choices=SessionStatusChoices,
choices=CommunityStatusChoices,
widget=StaticSelect()
)

Expand Down
15 changes: 5 additions & 10 deletions netbox_bgp/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion netbox_bgp/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.0"
__version__ = "0.8.0"

0 comments on commit 3480a88

Please sign in to comment.