Add fhrpgroup to IPAddressImportForm

This commit is contained in:
Renato Almeida de Oliveira Zaroubin 2025-03-19 02:00:36 +00:00
parent 7c152e9234
commit 98272c29f7

View File

@ -327,6 +327,13 @@ class IPAddressImportForm(NetBoxModelImportForm):
to_field_name='name',
help_text=_('Assigned interface')
)
fhrpgroup = CSVModelChoiceField(
label=_('FHRP Group (ID)'),
queryset=FHRPGroup.objects.all(),
required=False,
to_field_name='group_id',
help_text=_('Assigned FHRP Group ID')
)
is_primary = forms.BooleanField(
label=_('Is primary'),
help_text=_('Make this the primary IP for the assigned device'),
@ -341,8 +348,8 @@ class IPAddressImportForm(NetBoxModelImportForm):
class Meta:
model = IPAddress
fields = [
'address', 'vrf', 'tenant', 'status', 'role', 'device', 'virtual_machine', 'interface', 'is_primary',
'is_oob', 'dns_name', 'description', 'comments', 'tags',
'address', 'vrf', 'tenant', 'status', 'role', 'device', 'virtual_machine', 'interface', 'fhrpgroup',
'is_primary', 'is_oob', 'dns_name', 'description', 'comments', 'tags',
]
def __init__(self, data=None, *args, **kwargs):
@ -398,6 +405,8 @@ class IPAddressImportForm(NetBoxModelImportForm):
# Set interface assignment
if self.cleaned_data.get('interface'):
self.instance.assigned_object = self.cleaned_data['interface']
if self.cleaned_data.get('fhrpgroup'):
self.instance.assigned_object = self.cleaned_data['fhrpgroup']
ipaddress = super().save(*args, **kwargs)