1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #3868: Fix creation of interfaces for virtual machines

This commit is contained in:
Jeremy Stretch
2020-01-09 14:53:18 -05:00
parent 40fe6666e3
commit fe490d144a
6 changed files with 31 additions and 12 deletions

View File

@@ -99,7 +99,7 @@ class VirtualMachineWithConfigContextSerializer(VirtualMachineSerializer):
class InterfaceSerializer(TaggitSerializer, ValidatedModelSerializer):
virtual_machine = NestedVirtualMachineSerializer()
type = ChoiceField(choices=InterfaceTypeChoices, default=InterfaceTypeChoices.TYPE_VIRTUAL, required=False)
type = ChoiceField(choices=VMInterfaceTypeChoices, default=VMInterfaceTypeChoices.TYPE_VIRTUAL, required=False)
mode = ChoiceField(choices=InterfaceModeChoices, required=False, allow_null=True)
untagged_vlan = NestedVLANSerializer(required=False, allow_null=True)
tagged_vlans = SerializedPKRelatedField(

View File

@@ -1,3 +1,4 @@
from dcim.choices import InterfaceTypeChoices
from utilities.choices import ChoiceSet
@@ -22,3 +23,16 @@ class VirtualMachineStatusChoices(ChoiceSet):
STATUS_ACTIVE: 1,
STATUS_STAGED: 3,
}
#
# Interface types (for VirtualMachines)
#
class VMInterfaceTypeChoices(ChoiceSet):
TYPE_VIRTUAL = InterfaceTypeChoices.TYPE_VIRTUAL
CHOICES = (
(TYPE_VIRTUAL, 'Virtual'),
)

View File

@@ -2,7 +2,7 @@ from django import forms
from django.core.exceptions import ValidationError
from taggit.forms import TagField
from dcim.choices import InterfaceModeChoices, InterfaceTypeChoices
from dcim.choices import InterfaceModeChoices
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
@@ -18,10 +18,6 @@ from utilities.forms import (
from .choices import *
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine
VIFACE_TYPE_CHOICES = (
(InterfaceTypeChoices.TYPE_VIRTUAL, 'Virtual'),
)
#
# Cluster types
@@ -740,8 +736,8 @@ class InterfaceCreateForm(ComponentForm):
label='Name'
)
type = forms.ChoiceField(
choices=VIFACE_TYPE_CHOICES,
initial=InterfaceTypeChoices.TYPE_VIRTUAL,
choices=VMInterfaceTypeChoices,
initial=VMInterfaceTypeChoices.TYPE_VIRTUAL,
widget=forms.HiddenInput()
)
enabled = forms.BooleanField(
@@ -925,8 +921,8 @@ class VirtualMachineBulkAddComponentForm(BootstrapMixin, forms.Form):
class VirtualMachineBulkAddInterfaceForm(VirtualMachineBulkAddComponentForm):
type = forms.ChoiceField(
choices=VIFACE_TYPE_CHOICES,
initial=InterfaceTypeChoices.TYPE_VIRTUAL,
choices=VMInterfaceTypeChoices,
initial=VMInterfaceTypeChoices.TYPE_VIRTUAL,
widget=forms.HiddenInput()
)
enabled = forms.BooleanField(