Skip to content

Commit 447e108

Browse files
Fixes: #18656 Unable to import IP Address and assign to FHRP Group (#18950)
* Add fhrpgroup to IPAddressImportForm * Change fhrpgroup accessor to name * rename fhrpgroup to fhrp_group * Add fhrp_group to IPAddressTestCase csv_data
1 parent e186113 commit 447e108

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

netbox/ipam/forms/bulk_import.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ class IPAddressImportForm(NetBoxModelImportForm):
327327
to_field_name='name',
328328
help_text=_('Assigned interface')
329329
)
330+
fhrp_group = CSVModelChoiceField(
331+
label=_('FHRP Group'),
332+
queryset=FHRPGroup.objects.all(),
333+
required=False,
334+
to_field_name='name',
335+
help_text=_('Assigned FHRP Group name')
336+
)
330337
is_primary = forms.BooleanField(
331338
label=_('Is primary'),
332339
help_text=_('Make this the primary IP for the assigned device'),
@@ -341,8 +348,8 @@ class IPAddressImportForm(NetBoxModelImportForm):
341348
class Meta:
342349
model = IPAddress
343350
fields = [
344-
'address', 'vrf', 'tenant', 'status', 'role', 'device', 'virtual_machine', 'interface', 'is_primary',
345-
'is_oob', 'dns_name', 'description', 'comments', 'tags',
351+
'address', 'vrf', 'tenant', 'status', 'role', 'device', 'virtual_machine', 'interface', 'fhrp_group',
352+
'is_primary', 'is_oob', 'dns_name', 'description', 'comments', 'tags',
346353
]
347354

348355
def __init__(self, data=None, *args, **kwargs):
@@ -398,6 +405,8 @@ def save(self, *args, **kwargs):
398405
# Set interface assignment
399406
if self.cleaned_data.get('interface'):
400407
self.instance.assigned_object = self.cleaned_data['interface']
408+
if self.cleaned_data.get('fhrp_group'):
409+
self.instance.assigned_object = self.cleaned_data['fhrp_group']
401410

402411
ipaddress = super().save(*args, **kwargs)
403412

netbox/ipam/tests/test_views.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,24 @@ def setUpTestData(cls):
666666

667667
tags = create_tags('Alpha', 'Bravo', 'Charlie')
668668

669+
fhrp_groups = (
670+
FHRPGroup(
671+
name='FHRP Group 1',
672+
protocol=FHRPGroupProtocolChoices.PROTOCOL_HSRP,
673+
group_id=10
674+
),
675+
FHRPGroup(
676+
name='FHRP Group 2',
677+
protocol=FHRPGroupProtocolChoices.PROTOCOL_HSRP,
678+
group_id=20
679+
),
680+
FHRPGroup(
681+
name='FHRP Group 3',
682+
protocol=FHRPGroupProtocolChoices.PROTOCOL_HSRP,
683+
group_id=30
684+
),
685+
)
686+
FHRPGroup.objects.bulk_create(fhrp_groups)
669687
cls.form_data = {
670688
'vrf': vrfs[1].pk,
671689
'address': IPNetwork('192.0.2.99/24'),
@@ -679,10 +697,10 @@ def setUpTestData(cls):
679697
}
680698

681699
cls.csv_data = (
682-
"vrf,address,status",
683-
"VRF 1,192.0.2.4/24,active",
684-
"VRF 1,192.0.2.5/24,active",
685-
"VRF 1,192.0.2.6/24,active",
700+
"vrf,address,status,fhrp_group",
701+
"VRF 1,192.0.2.4/24,active,FHRP Group 1",
702+
"VRF 1,192.0.2.5/24,active,FHRP Group 2",
703+
"VRF 1,192.0.2.6/24,active,FHRP Group 3",
686704
)
687705

688706
cls.csv_update_data = (

0 commit comments

Comments
 (0)