|
@@ -2044,6 +2044,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
|
|
|
type = ChoiceField(
|
|
type = ChoiceField(
|
|
|
label=_('Type'),
|
|
label=_('Type'),
|
|
|
choices=InterfaceTypeChoices,
|
|
choices=InterfaceTypeChoices,
|
|
|
|
|
+ widget=HTMXSelect(hx_target_id='lag-attributes'),
|
|
|
)
|
|
)
|
|
|
duplex = TypedChoiceField(
|
|
duplex = TypedChoiceField(
|
|
|
label=_('Duplex'),
|
|
label=_('Duplex'),
|
|
@@ -2060,6 +2061,17 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
|
|
|
choices=add_blank_choice(InterfacePoETypeChoices),
|
|
choices=add_blank_choice(InterfacePoETypeChoices),
|
|
|
required=False,
|
|
required=False,
|
|
|
)
|
|
)
|
|
|
|
|
+ lag_mode = TypedChoiceField(
|
|
|
|
|
+ label=_('LAG mode'),
|
|
|
|
|
+ choices=add_blank_choice(InterfaceLAGModeChoices),
|
|
|
|
|
+ required=False,
|
|
|
|
|
+ widget=HTMXSelect(hx_target_id='lag-attributes'),
|
|
|
|
|
+ )
|
|
|
|
|
+ lag_hash_policy = TypedChoiceField(
|
|
|
|
|
+ label=_('LAG hash policy'),
|
|
|
|
|
+ choices=add_blank_choice(InterfaceLAGHashPolicyChoices),
|
|
|
|
|
+ required=False,
|
|
|
|
|
+ )
|
|
|
mode = TypedChoiceField(
|
|
mode = TypedChoiceField(
|
|
|
label=_('802.1Q Mode'),
|
|
label=_('802.1Q Mode'),
|
|
|
choices=add_blank_choice(InterfaceModeChoices),
|
|
choices=add_blank_choice(InterfaceModeChoices),
|
|
@@ -2185,6 +2197,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
|
|
|
FieldSet('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected', name=_('Operation')),
|
|
FieldSet('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected', name=_('Operation')),
|
|
|
FieldSet('parent', 'channel_id', 'bridge', 'lag', name=_('Related Interfaces')),
|
|
FieldSet('parent', 'channel_id', 'bridge', 'lag', name=_('Related Interfaces')),
|
|
|
FieldSet('poe_mode', 'poe_type', name=_('PoE')),
|
|
FieldSet('poe_mode', 'poe_type', name=_('PoE')),
|
|
|
|
|
+ FieldSet('lag_mode', 'lag_hash_policy', name=_('LAG'), html_id='lag-attributes'),
|
|
|
FieldSet(
|
|
FieldSet(
|
|
|
'mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy',
|
|
'mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy',
|
|
|
name=_('802.1Q Switching'),
|
|
name=_('802.1Q Switching'),
|
|
@@ -2199,11 +2212,11 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = Interface
|
|
model = Interface
|
|
|
fields = [
|
|
fields = [
|
|
|
- 'device', 'module', 'vdcs', 'name', 'label', 'type', 'channels', 'channel_id', 'speed', 'duplex',
|
|
|
|
|
- 'enabled', 'parent', 'bridge', 'lag', 'wwn', 'mtu', 'mgmt_only', 'mark_connected', 'description',
|
|
|
|
|
- 'poe_mode', 'poe_type', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width',
|
|
|
|
|
- 'tx_power', 'wireless_lans', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy',
|
|
|
|
|
- 'vrf', 'owner', 'tags',
|
|
|
|
|
|
|
+ 'device', 'module', 'vdcs', 'name', 'label', 'type', 'channels', 'channel_id', 'speed', 'duplex', 'enabled',
|
|
|
|
|
+ 'parent', 'bridge', 'lag', 'wwn', 'mtu', 'mgmt_only', 'mark_connected', 'description', 'poe_mode',
|
|
|
|
|
+ 'poe_type', 'lag_mode', 'lag_hash_policy', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
|
|
|
|
+ 'rf_channel_width', 'tx_power', 'wireless_lans', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan',
|
|
|
|
|
+ 'vlan_translation_policy', 'vrf', 'owner', 'tags',
|
|
|
]
|
|
]
|
|
|
widgets = {
|
|
widgets = {
|
|
|
'speed': NumberWithOptions(
|
|
'speed': NumberWithOptions(
|
|
@@ -2211,6 +2224,31 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
|
|
|
),
|
|
),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
|
|
+ super().__init__(*args, **kwargs)
|
|
|
|
|
+
|
|
|
|
|
+ # LAG attributes apply only to LAG interfaces, and a hash policy only to LAG modes which hash
|
|
|
|
|
+ if get_field_value(self, 'type') != InterfaceTypeChoices.TYPE_LAG:
|
|
|
|
|
+ del self.fields['lag_mode']
|
|
|
|
|
+ del self.fields['lag_hash_policy']
|
|
|
|
|
+ else:
|
|
|
|
|
+ # Read a submitted mode directly, as get_field_value() treats a cleared (blank) mode as unset
|
|
|
|
|
+ if self.is_bound and 'lag_mode' in self.data:
|
|
|
|
|
+ lag_mode = self.data['lag_mode']
|
|
|
|
|
+ else:
|
|
|
|
|
+ lag_mode = get_field_value(self, 'lag_mode')
|
|
|
|
|
+ if lag_mode not in LAG_HASH_MODES:
|
|
|
|
|
+ del self.fields['lag_hash_policy']
|
|
|
|
|
+
|
|
|
|
|
+ def clean(self):
|
|
|
|
|
+ super().clean()
|
|
|
|
|
+
|
|
|
|
|
+ # Clear any LAG attributes which no longer apply
|
|
|
|
|
+ if 'lag_mode' not in self.fields:
|
|
|
|
|
+ self.instance.lag_mode = None
|
|
|
|
|
+ if 'lag_hash_policy' not in self.fields:
|
|
|
|
|
+ self.instance.lag_hash_policy = None
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class FrontPortForm(FrontPortFormMixin, ModularDeviceComponentForm):
|
|
class FrontPortForm(FrontPortFormMixin, ModularDeviceComponentForm):
|
|
|
type = ChoiceField(
|
|
type = ChoiceField(
|