瀏覽代碼

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

jeremystretch 4 年之前
父節點
當前提交
dfdeac4968
共有 2 個文件被更改,包括 9 次插入1 次删除
  1. 1 0
      docs/release-notes/version-3.0.md
  2. 8 1
      netbox/ipam/forms/bulk_import.py

+ 1 - 0
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
 
 ---
 

+ 8 - 1
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):