mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
IPAddress.status to slug (#3569)
This commit is contained in:
@ -201,7 +201,7 @@ class IPAddressSerializer(TaggitSerializer, CustomFieldModelSerializer):
|
|||||||
family = ChoiceField(choices=AF_CHOICES, read_only=True)
|
family = ChoiceField(choices=AF_CHOICES, read_only=True)
|
||||||
vrf = NestedVRFSerializer(required=False, allow_null=True)
|
vrf = NestedVRFSerializer(required=False, allow_null=True)
|
||||||
tenant = NestedTenantSerializer(required=False, allow_null=True)
|
tenant = NestedTenantSerializer(required=False, allow_null=True)
|
||||||
status = ChoiceField(choices=IPADDRESS_STATUS_CHOICES, required=False)
|
status = ChoiceField(choices=IPAddressStatusChoices, required=False)
|
||||||
role = ChoiceField(choices=IPADDRESS_ROLE_CHOICES, required=False, allow_null=True)
|
role = ChoiceField(choices=IPADDRESS_ROLE_CHOICES, required=False, allow_null=True)
|
||||||
interface = IPAddressInterfaceSerializer(required=False, allow_null=True)
|
interface = IPAddressInterfaceSerializer(required=False, allow_null=True)
|
||||||
nat_inside = NestedIPAddressSerializer(required=False, allow_null=True)
|
nat_inside = NestedIPAddressSerializer(required=False, allow_null=True)
|
||||||
|
@ -25,3 +25,29 @@ class PrefixStatusChoices(ChoiceSet):
|
|||||||
STATUS_RESERVED: 2,
|
STATUS_RESERVED: 2,
|
||||||
STATUS_DEPRECATED: 3,
|
STATUS_DEPRECATED: 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# IPAddresses
|
||||||
|
#
|
||||||
|
|
||||||
|
class IPAddressStatusChoices(ChoiceSet):
|
||||||
|
|
||||||
|
STATUS_ACTIVE = 'active'
|
||||||
|
STATUS_RESERVED = 'reserved'
|
||||||
|
STATUS_DEPRECATED = 'deprecated'
|
||||||
|
STATUS_DHCP = 'dhcp'
|
||||||
|
|
||||||
|
CHOICES = (
|
||||||
|
(STATUS_ACTIVE, 'Active'),
|
||||||
|
(STATUS_RESERVED, 'Reserved'),
|
||||||
|
(STATUS_DEPRECATED, 'Deprecated'),
|
||||||
|
(STATUS_DHCP, 'DHCP'),
|
||||||
|
)
|
||||||
|
|
||||||
|
LEGACY_MAP = {
|
||||||
|
STATUS_ACTIVE: 1,
|
||||||
|
STATUS_RESERVED: 2,
|
||||||
|
STATUS_DEPRECATED: 3,
|
||||||
|
STATUS_DHCP: 5,
|
||||||
|
}
|
||||||
|
@ -4,18 +4,6 @@ AF_CHOICES = (
|
|||||||
(6, 'IPv6'),
|
(6, 'IPv6'),
|
||||||
)
|
)
|
||||||
|
|
||||||
# IP address statuses
|
|
||||||
IPADDRESS_STATUS_ACTIVE = 1
|
|
||||||
IPADDRESS_STATUS_RESERVED = 2
|
|
||||||
IPADDRESS_STATUS_DEPRECATED = 3
|
|
||||||
IPADDRESS_STATUS_DHCP = 5
|
|
||||||
IPADDRESS_STATUS_CHOICES = (
|
|
||||||
(IPADDRESS_STATUS_ACTIVE, 'Active'),
|
|
||||||
(IPADDRESS_STATUS_RESERVED, 'Reserved'),
|
|
||||||
(IPADDRESS_STATUS_DEPRECATED, 'Deprecated'),
|
|
||||||
(IPADDRESS_STATUS_DHCP, 'DHCP')
|
|
||||||
)
|
|
||||||
|
|
||||||
# IP address roles
|
# IP address roles
|
||||||
IPADDRESS_ROLE_LOOPBACK = 10
|
IPADDRESS_ROLE_LOOPBACK = 10
|
||||||
IPADDRESS_ROLE_SECONDARY = 20
|
IPADDRESS_ROLE_SECONDARY = 20
|
||||||
|
@ -311,7 +311,7 @@ class IPAddressFilter(TenancyFilterSet, CustomFieldFilterSet):
|
|||||||
label='Interface (ID)',
|
label='Interface (ID)',
|
||||||
)
|
)
|
||||||
status = django_filters.MultipleChoiceFilter(
|
status = django_filters.MultipleChoiceFilter(
|
||||||
choices=IPADDRESS_STATUS_CHOICES,
|
choices=IPAddressStatusChoices,
|
||||||
null_value=None
|
null_value=None
|
||||||
)
|
)
|
||||||
role = django_filters.MultipleChoiceFilter(
|
role = django_filters.MultipleChoiceFilter(
|
||||||
|
@ -765,7 +765,7 @@ class IPAddressCSVForm(forms.ModelForm):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
status = CSVChoiceField(
|
status = CSVChoiceField(
|
||||||
choices=IPADDRESS_STATUS_CHOICES,
|
choices=IPAddressStatusChoices,
|
||||||
help_text='Operational status'
|
help_text='Operational status'
|
||||||
)
|
)
|
||||||
role = CSVChoiceField(
|
role = CSVChoiceField(
|
||||||
@ -894,7 +894,7 @@ class IPAddressBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
status = forms.ChoiceField(
|
status = forms.ChoiceField(
|
||||||
choices=add_blank_choice(IPADDRESS_STATUS_CHOICES),
|
choices=add_blank_choice(IPAddressStatusChoices),
|
||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
@ -973,7 +973,7 @@ class IPAddressFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterFo
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
status = forms.MultipleChoiceField(
|
status = forms.MultipleChoiceField(
|
||||||
choices=IPADDRESS_STATUS_CHOICES,
|
choices=IPAddressStatusChoices,
|
||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2Multiple()
|
widget=StaticSelect2Multiple()
|
||||||
)
|
)
|
||||||
|
37
netbox/ipam/migrations/0029_3569_ipaddress_fields.py
Normal file
37
netbox/ipam/migrations/0029_3569_ipaddress_fields.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
IPADDRESS_STATUS_CHOICES = (
|
||||||
|
(0, 'container'),
|
||||||
|
(1, 'active'),
|
||||||
|
(2, 'reserved'),
|
||||||
|
(3, 'deprecated'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def ipaddress_status_to_slug(apps, schema_editor):
|
||||||
|
IPAddress = apps.get_model('ipam', 'IPAddress')
|
||||||
|
for id, slug in IPADDRESS_STATUS_CHOICES:
|
||||||
|
IPAddress.objects.filter(status=str(id)).update(status=slug)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
atomic = False
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('ipam', '0028_3569_prefix_fields'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
|
||||||
|
# IPAddress.status
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ipaddress',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(default='active', max_length=50),
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=ipaddress_status_to_slug
|
||||||
|
),
|
||||||
|
|
||||||
|
]
|
@ -559,10 +559,10 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
status = models.PositiveSmallIntegerField(
|
status = models.CharField(
|
||||||
choices=IPADDRESS_STATUS_CHOICES,
|
max_length=50,
|
||||||
default=IPADDRESS_STATUS_ACTIVE,
|
choices=IPAddressStatusChoices,
|
||||||
verbose_name='Status',
|
default=IPAddressStatusChoices.STATUS_ACTIVE,
|
||||||
help_text='The operational status of this IP'
|
help_text='The operational status of this IP'
|
||||||
)
|
)
|
||||||
role = models.PositiveSmallIntegerField(
|
role = models.PositiveSmallIntegerField(
|
||||||
@ -613,6 +613,13 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|||||||
'dns_name', 'description',
|
'dns_name', 'description',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
STATUS_CLASS_MAP = {
|
||||||
|
'active': 'primary',
|
||||||
|
'reserved': 'info',
|
||||||
|
'deprecated': 'danger',
|
||||||
|
'dhcp': 'success',
|
||||||
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['family', 'address']
|
ordering = ['family', 'address']
|
||||||
verbose_name = 'IP address'
|
verbose_name = 'IP address'
|
||||||
@ -746,7 +753,7 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_status_class(self):
|
def get_status_class(self):
|
||||||
return STATUS_CHOICE_CLASSES[self.status]
|
return self.STATUS_CLASS_MAP.get(self.status)
|
||||||
|
|
||||||
def get_role_class(self):
|
def get_role_class(self):
|
||||||
return ROLE_CHOICE_CLASSES[self.role]
|
return ROLE_CHOICE_CLASSES[self.role]
|
||||||
|
Reference in New Issue
Block a user