From 650783b0856f36b4e463ee9a6b8f57689b51993c Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Wed, 27 Sep 2023 11:25:25 +0530 Subject: [PATCH 1/5] issue 13022 resolved, ipaddress added into bulk_import form --- netbox/ipam/forms/bulk_import.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index ac3c994681e..661d28990b9 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -507,10 +507,16 @@ class ServiceImportForm(NetBoxModelImportForm): choices=ServiceProtocolChoices, help_text=_('IP protocol') ) + ipaddresses = CSVModelMultipleChoiceField( + queryset=IPAddress.objects.all(), + required=False, + to_field_name='address', + help_text=_('IP Address'), + ) class Meta: model = Service - fields = ('device', 'virtual_machine', 'name', 'protocol', 'ports', 'description', 'comments', 'tags') + fields = ('device', 'virtual_machine', 'ipaddresses', 'name', 'protocol', 'ports', 'description', 'comments', 'tags') class L2VPNImportForm(NetBoxModelImportForm): From 518ee85d9e6cbd35d2cd05471474f296d7452fd6 Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Tue, 10 Oct 2023 17:58:07 +0530 Subject: [PATCH 2/5] validation of ip address for device and virtual machine --- netbox/ipam/forms/bulk_import.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index 661d28990b9..a6ec544cfb0 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -516,7 +516,21 @@ class ServiceImportForm(NetBoxModelImportForm): class Meta: model = Service - fields = ('device', 'virtual_machine', 'ipaddresses', 'name', 'protocol', 'ports', 'description', 'comments', 'tags') + fields = ( + 'device', 'virtual_machine', 'ipaddresses', 'name', 'protocol', 'ports', 'description', 'comments', 'tags') + + def clean_ipaddresses(self): + + device = self.cleaned_data.get('device') + virtual_machine = self.cleaned_data.get('virtual_machine') + + for ip_address in self.cleaned_data.get('ipaddresses'): + if device and ip_address != device.primary_ip4: + raise forms.ValidationError("Device should assign to be an ip address") + if virtual_machine and ip_address != virtual_machine.primary_ip4: + raise forms.ValidationError("Virtual Machine should assign to be an ip address") + + return self.cleaned_data class L2VPNImportForm(NetBoxModelImportForm): From 995586458a7a5e2fdc8341f9a7dd5b7a1bb0d940 Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Tue, 10 Oct 2023 18:37:21 +0530 Subject: [PATCH 3/5] error message modified --- netbox/ipam/forms/bulk_import.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index a6ec544cfb0..449053e1b28 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -526,9 +526,11 @@ def clean_ipaddresses(self): for ip_address in self.cleaned_data.get('ipaddresses'): if device and ip_address != device.primary_ip4: - raise forms.ValidationError("Device should assign to be an ip address") + raise forms.ValidationError( + f"IP address assignment required for the device.") if virtual_machine and ip_address != virtual_machine.primary_ip4: - raise forms.ValidationError("Virtual Machine should assign to be an ip address") + raise forms.ValidationError( + f"IP address assignment required for the virtual machine.") return self.cleaned_data From fc616301e9b4c4b6ff8dacb3af18053af4a09609 Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Tue, 10 Oct 2023 19:03:34 +0530 Subject: [PATCH 4/5] error message modified --- netbox/ipam/forms/bulk_import.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index 449053e1b28..cbc97ca49a1 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -526,11 +526,9 @@ def clean_ipaddresses(self): for ip_address in self.cleaned_data.get('ipaddresses'): if device and ip_address != device.primary_ip4: - raise forms.ValidationError( - f"IP address assignment required for the device.") + raise forms.ValidationError("Device needs to be assign an IPAddress") if virtual_machine and ip_address != virtual_machine.primary_ip4: - raise forms.ValidationError( - f"IP address assignment required for the virtual machine.") + raise forms.ValidationError("Virtual Machine needs to be assign an IPAddress") return self.cleaned_data From ade0eda9e02bd030130c0018159c7f418c63e5bb Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Tue, 10 Oct 2023 19:07:51 +0530 Subject: [PATCH 5/5] error message modified --- netbox/ipam/forms/bulk_import.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index cbc97ca49a1..3010debab87 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -526,9 +526,9 @@ def clean_ipaddresses(self): for ip_address in self.cleaned_data.get('ipaddresses'): if device and ip_address != device.primary_ip4: - raise forms.ValidationError("Device needs to be assign an IPAddress") + raise forms.ValidationError(f"Device is not assigned to this {ip_address}") if virtual_machine and ip_address != virtual_machine.primary_ip4: - raise forms.ValidationError("Virtual Machine needs to be assign an IPAddress") + raise forms.ValidationError(f"Virtual Machine is not assigned to this {ip_address}") return self.cleaned_data