Fixes #7647: Require interface assignment when designating IP address as primary for device/VM during CSV import

This commit is contained in:
jeremystretch 2021-10-27 10:20:17 -04:00
parent e84f2e3ad2
commit dfdeac4968
2 changed files with 9 additions and 1 deletions

View File

@ -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
---

View File

@ -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):