From dfdeac496832820917aa18993ee52e7a44fe00b5 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 27 Oct 2021 10:20:17 -0400 Subject: [PATCH] Fixes #7647: Require interface assignment when designating IP address as primary for device/VM during CSV import --- docs/release-notes/version-3.0.md | 1 + netbox/ipam/forms/bulk_import.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index cba7e56f1..32d40ada3 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -9,6 +9,7 @@ * [#7628](https://github.com/netbox-community/netbox/issues/7628) - Fix `load_yaml` method for custom scripts * [#7643](https://github.com/netbox-community/netbox/issues/7643) - Fix circuit assignment when creating multiple terminations simultaneously * [#7644](https://github.com/netbox-community/netbox/issues/7644) - Prevent inadvertent deletion of prior change records when deleting objects (#7333 revisited) +* [#7647](https://github.com/netbox-community/netbox/issues/7647) - Require interface assignment when designating IP address as primary for device/VM during CSV import --- diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index 49d5014f9..3d7c829d6 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -257,11 +257,18 @@ class IPAddressCSVForm(CustomFieldModelCSVForm): device = self.cleaned_data.get('device') virtual_machine = self.cleaned_data.get('virtual_machine') + interface = self.cleaned_data.get('interface') is_primary = self.cleaned_data.get('is_primary') # Validate is_primary if is_primary and not device and not virtual_machine: - raise forms.ValidationError("No device or virtual machine specified; cannot set as primary IP") + raise forms.ValidationError({ + "is_primary": "No device or virtual machine specified; cannot set as primary IP" + }) + if is_primary and not interface: + raise forms.ValidationError({ + "is_primary": "No interface specified; cannot set as primary IP" + }) def save(self, *args, **kwargs):