Allow interface mode to be null (for routed interfaces)

This commit is contained in:
Jeremy Stretch 2018-01-25 11:45:12 -05:00
parent 9a6a479452
commit 4a57a554da
3 changed files with 10 additions and 7 deletions

View File

@ -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(

View File

@ -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',

View File

@ -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,