mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-26 07:07:46 -06:00
Interface.type to slug (#3569)
This commit is contained in:
@@ -3,7 +3,8 @@ from rest_framework import serializers
|
||||
from taggit_serializer.serializers import TaggitSerializer, TagListSerializerField
|
||||
|
||||
from dcim.api.nested_serializers import NestedDeviceRoleSerializer, NestedPlatformSerializer, NestedSiteSerializer
|
||||
from dcim.constants import IFACE_TYPE_CHOICES, IFACE_TYPE_VIRTUAL, IFACE_MODE_CHOICES
|
||||
from dcim.choices import InterfaceTypeChoices
|
||||
from dcim.constants import IFACE_MODE_CHOICES
|
||||
from dcim.models import Interface
|
||||
from extras.api.customfields import CustomFieldModelSerializer
|
||||
from ipam.api.nested_serializers import NestedIPAddressSerializer, NestedVLANSerializer
|
||||
@@ -98,7 +99,7 @@ class VirtualMachineWithConfigContextSerializer(VirtualMachineSerializer):
|
||||
|
||||
class InterfaceSerializer(TaggitSerializer, ValidatedModelSerializer):
|
||||
virtual_machine = NestedVirtualMachineSerializer()
|
||||
type = ChoiceField(choices=IFACE_TYPE_CHOICES, default=IFACE_TYPE_VIRTUAL, required=False)
|
||||
type = ChoiceField(choices=InterfaceTypeChoices, default=InterfaceTypeChoices.TYPE_VIRTUAL, required=False)
|
||||
mode = ChoiceField(choices=IFACE_MODE_CHOICES, required=False, allow_null=True)
|
||||
untagged_vlan = NestedVLANSerializer(required=False, allow_null=True)
|
||||
tagged_vlans = SerializedPKRelatedField(
|
||||
|
||||
@@ -2,7 +2,8 @@ from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from taggit.forms import TagField
|
||||
|
||||
from dcim.constants import IFACE_TYPE_VIRTUAL, IFACE_MODE_ACCESS, IFACE_MODE_TAGGED_ALL, IFACE_MODE_CHOICES
|
||||
from dcim.choices import InterfaceTypeChoices
|
||||
from dcim.constants import IFACE_MODE_ACCESS, IFACE_MODE_TAGGED_ALL, IFACE_MODE_CHOICES
|
||||
from dcim.forms import INTERFACE_MODE_HELP_TEXT
|
||||
from dcim.models import Device, DeviceRole, Interface, Platform, Rack, Region, Site
|
||||
from extras.forms import AddRemoveTagsForm, CustomFieldBulkEditForm, CustomFieldForm, CustomFieldFilterForm
|
||||
@@ -19,7 +20,7 @@ from .constants import *
|
||||
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine
|
||||
|
||||
VIFACE_TYPE_CHOICES = (
|
||||
(IFACE_TYPE_VIRTUAL, 'Virtual'),
|
||||
(InterfaceTypeChoices.TYPE_VIRTUAL, 'Virtual'),
|
||||
)
|
||||
|
||||
|
||||
@@ -733,7 +734,7 @@ class InterfaceCreateForm(ComponentForm):
|
||||
)
|
||||
type = forms.ChoiceField(
|
||||
choices=VIFACE_TYPE_CHOICES,
|
||||
initial=IFACE_TYPE_VIRTUAL,
|
||||
initial=InterfaceTypeChoices.TYPE_VIRTUAL,
|
||||
widget=forms.HiddenInput()
|
||||
)
|
||||
enabled = forms.BooleanField(
|
||||
@@ -918,7 +919,7 @@ class VirtualMachineBulkAddComponentForm(BootstrapMixin, forms.Form):
|
||||
class VirtualMachineBulkAddInterfaceForm(VirtualMachineBulkAddComponentForm):
|
||||
type = forms.ChoiceField(
|
||||
choices=VIFACE_TYPE_CHOICES,
|
||||
initial=IFACE_TYPE_VIRTUAL,
|
||||
initial=InterfaceTypeChoices.TYPE_VIRTUAL,
|
||||
widget=forms.HiddenInput()
|
||||
)
|
||||
enabled = forms.BooleanField(
|
||||
|
||||
@@ -2,7 +2,8 @@ from django.urls import reverse
|
||||
from netaddr import IPNetwork
|
||||
from rest_framework import status
|
||||
|
||||
from dcim.constants import IFACE_TYPE_VIRTUAL, IFACE_MODE_TAGGED
|
||||
from dcim.choices import InterfaceTypeChoices
|
||||
from dcim.constants import IFACE_MODE_TAGGED
|
||||
from dcim.models import Interface
|
||||
from ipam.models import IPAddress, VLAN
|
||||
from utilities.testing import APITestCase
|
||||
@@ -489,17 +490,17 @@ class InterfaceTest(APITestCase):
|
||||
self.interface1 = Interface.objects.create(
|
||||
virtual_machine=self.virtualmachine,
|
||||
name='Test Interface 1',
|
||||
type=IFACE_TYPE_VIRTUAL
|
||||
type=InterfaceTypeChoices.TYPE_VIRTUAL
|
||||
)
|
||||
self.interface2 = Interface.objects.create(
|
||||
virtual_machine=self.virtualmachine,
|
||||
name='Test Interface 2',
|
||||
type=IFACE_TYPE_VIRTUAL
|
||||
type=InterfaceTypeChoices.TYPE_VIRTUAL
|
||||
)
|
||||
self.interface3 = Interface.objects.create(
|
||||
virtual_machine=self.virtualmachine,
|
||||
name='Test Interface 3',
|
||||
type=IFACE_TYPE_VIRTUAL
|
||||
type=InterfaceTypeChoices.TYPE_VIRTUAL
|
||||
)
|
||||
|
||||
self.vlan1 = VLAN.objects.create(name="Test VLAN 1", vid=1)
|
||||
|
||||
Reference in New Issue
Block a user