From 4a57a554da543810d5c4a9db806db0d6a86805c7 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 25 Jan 2018 11:45:12 -0500 Subject: [PATCH] Allow interface mode to be null (for routed interfaces) --- netbox/dcim/forms.py | 9 ++++----- netbox/dcim/migrations/0050_interface_vlan_tagging.py | 2 +- netbox/dcim/models.py | 6 +++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 91206e78d..c45996286 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -1632,11 +1632,10 @@ class PowerOutletBulkDisconnectForm(ConfirmationForm): # class InterfaceForm(BootstrapMixin, forms.ModelForm, ChainedFieldsMixin): - site = forms.ModelChoiceField( queryset=Site.objects.all(), required=False, - label='VLAN Site', + label='VLAN site', widget=forms.Select( attrs={'filter-for': 'vlan_group', 'nullable': 'true'}, ) @@ -1681,8 +1680,8 @@ class InterfaceForm(BootstrapMixin, forms.ModelForm, ChainedFieldsMixin): class Meta: model = Interface fields = [ - 'device', 'name', 'form_factor', 'enabled', 'lag', 'mac_address', 'mtu', 'mgmt_only', - 'description', 'mode', 'site', 'vlan_group', 'untagged_vlan', 'tagged_vlans', + 'device', 'name', 'form_factor', 'enabled', 'lag', 'mac_address', 'mtu', 'mgmt_only', 'description', + 'mode', 'site', 'vlan_group', 'untagged_vlan', 'tagged_vlans', ] widgets = { 'device': forms.HiddenInput(), @@ -1738,7 +1737,7 @@ class InterfaceForm(BootstrapMixin, forms.ModelForm, ChainedFieldsMixin): def clean_tagged_vlans(self): """ - Becasue tagged_vlans is a many-to-many relationship, validation must be done in the form + Because tagged_vlans is a many-to-many relationship, validation must be done in the form """ if self.cleaned_data['mode'] == IFACE_MODE_ACCESS and self.cleaned_data['tagged_vlans']: raise forms.ValidationError( diff --git a/netbox/dcim/migrations/0050_interface_vlan_tagging.py b/netbox/dcim/migrations/0050_interface_vlan_tagging.py index cb44054a7..1906b9179 100644 --- a/netbox/dcim/migrations/0050_interface_vlan_tagging.py +++ b/netbox/dcim/migrations/0050_interface_vlan_tagging.py @@ -17,7 +17,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='interface', name='mode', - field=models.PositiveSmallIntegerField(choices=[[100, 'Access'], [200, 'Tagged'], [300, 'Tagged All']], default=100), + field=models.PositiveSmallIntegerField(blank=True, choices=[[100, 'Access'], [200, 'Tagged'], [300, 'Tagged All']], null=True), ), migrations.AddField( model_name='interface', diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index a781ebd7b..59a41a9da 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -1308,7 +1308,11 @@ class Interface(models.Model): help_text="This interface is used only for out-of-band management" ) description = models.CharField(max_length=100, blank=True) - mode = models.PositiveSmallIntegerField(choices=IFACE_MODE_CHOICES, default=IFACE_MODE_ACCESS) + mode = models.PositiveSmallIntegerField( + choices=IFACE_MODE_CHOICES, + blank=True, + null=True + ) untagged_vlan = models.ForeignKey( to='ipam.VLAN', null=True,