mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-25 12:59:59 -06:00
Merge branch 'develop' into feature
This commit is contained in:
@@ -13,7 +13,7 @@ class VirtualMachineBulkAddComponentForm(BootstrapMixin, forms.Form):
|
||||
queryset=VirtualMachine.objects.all(),
|
||||
widget=forms.MultipleHiddenInput()
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
name = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
|
||||
@@ -27,4 +27,4 @@ class VMInterfaceBulkCreateForm(
|
||||
form_from_model(VMInterface, ['enabled', 'mtu', 'description', 'tags']),
|
||||
VirtualMachineBulkAddComponentForm
|
||||
):
|
||||
pass
|
||||
replication_fields = ('name',)
|
||||
|
||||
@@ -5,7 +5,6 @@ from django.core.exceptions import ValidationError
|
||||
from dcim.forms.common import InterfaceCommonForm
|
||||
from dcim.forms.models import INTERFACE_MODE_HELP_TEXT
|
||||
from dcim.models import Device, DeviceRole, Platform, Rack, Region, Site, SiteGroup
|
||||
from extras.models import Tag
|
||||
from ipam.models import IPAddress, VLAN, VLANGroup, VRF
|
||||
from netbox.forms import NetBoxModelForm
|
||||
from tenancy.forms import TenancyForm
|
||||
@@ -278,6 +277,9 @@ class VirtualMachineForm(TenancyForm, NetBoxModelForm):
|
||||
|
||||
|
||||
class VMInterfaceForm(InterfaceCommonForm, NetBoxModelForm):
|
||||
virtual_machine = DynamicModelChoiceField(
|
||||
queryset=VirtualMachine.objects.all()
|
||||
)
|
||||
parent = DynamicModelChoiceField(
|
||||
queryset=VMInterface.objects.all(),
|
||||
required=False,
|
||||
@@ -338,7 +340,6 @@ class VMInterfaceForm(InterfaceCommonForm, NetBoxModelForm):
|
||||
'vlan_group', 'untagged_vlan', 'tagged_vlans', 'vrf', 'tags',
|
||||
]
|
||||
widgets = {
|
||||
'virtual_machine': forms.HiddenInput(),
|
||||
'mode': StaticSelect()
|
||||
}
|
||||
labels = {
|
||||
@@ -347,3 +348,10 @@ class VMInterfaceForm(InterfaceCommonForm, NetBoxModelForm):
|
||||
help_texts = {
|
||||
'mode': INTERFACE_MODE_HELP_TEXT,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Disable reassignment of VirtualMachine when editing an existing instance
|
||||
if self.instance.pk:
|
||||
self.fields['virtual_machine'].disabled = True
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
from django import forms
|
||||
|
||||
from utilities.forms import BootstrapMixin, DynamicModelChoiceField, ExpandableNameField
|
||||
from .models import VirtualMachine
|
||||
from utilities.forms import ExpandableNameField
|
||||
from .models import VMInterfaceForm
|
||||
|
||||
__all__ = (
|
||||
'VMInterfaceCreateForm',
|
||||
)
|
||||
|
||||
|
||||
class VMInterfaceCreateForm(BootstrapMixin, forms.Form):
|
||||
virtual_machine = DynamicModelChoiceField(
|
||||
queryset=VirtualMachine.objects.all()
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
class VMInterfaceCreateForm(VMInterfaceForm):
|
||||
name = ExpandableNameField()
|
||||
replication_fields = ('name',)
|
||||
|
||||
class Meta(VMInterfaceForm.Meta):
|
||||
exclude = ('name',)
|
||||
|
||||
@@ -251,6 +251,7 @@ class VirtualMachineTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
|
||||
class VMInterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase):
|
||||
model = VMInterface
|
||||
validation_excluded_fields = ('name',)
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@@ -290,10 +291,10 @@ class VMInterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase):
|
||||
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
||||
|
||||
cls.form_data = {
|
||||
'virtual_machine': virtualmachines[1].pk,
|
||||
'virtual_machine': virtualmachines[0].pk,
|
||||
'name': 'Interface X',
|
||||
'enabled': False,
|
||||
'bridge': interfaces[3].pk,
|
||||
'bridge': interfaces[1].pk,
|
||||
'mac_address': EUI('01-02-03-04-05-06'),
|
||||
'mtu': 65000,
|
||||
'description': 'New description',
|
||||
@@ -306,7 +307,7 @@ class VMInterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase):
|
||||
|
||||
cls.bulk_create_data = {
|
||||
'virtual_machine': virtualmachines[1].pk,
|
||||
'name_pattern': 'Interface [4-6]',
|
||||
'name': 'Interface [4-6]',
|
||||
'enabled': False,
|
||||
'bridge': interfaces[3].pk,
|
||||
'mac_address': EUI('01-02-03-04-05-06'),
|
||||
|
||||
@@ -451,13 +451,11 @@ class VMInterfaceCreateView(generic.ComponentCreateView):
|
||||
queryset = VMInterface.objects.all()
|
||||
form = forms.VMInterfaceCreateForm
|
||||
model_form = forms.VMInterfaceForm
|
||||
patterned_fields = ('name',)
|
||||
|
||||
|
||||
class VMInterfaceEditView(generic.ObjectEditView):
|
||||
queryset = VMInterface.objects.all()
|
||||
form = forms.VMInterfaceForm
|
||||
template_name = 'virtualization/vminterface_edit.html'
|
||||
|
||||
|
||||
class VMInterfaceDeleteView(generic.ObjectDeleteView):
|
||||
|
||||
Reference in New Issue
Block a user