Explorar el Código

Fixes #9728: Fix validation when assigning a virtual machine to a device

jeremystretch hace 3 años
padre
commit
024e7d8651

+ 5 - 1
docs/release-notes/version-3.3.md

@@ -1,6 +1,6 @@
 # NetBox v3.3
 # NetBox v3.3
 
 
-## v3.3-beta1 (2022-07-14)
+## v3.3.0 (FUTURE)
 
 
 ### Breaking Changes
 ### Breaking Changes
 
 
@@ -96,6 +96,10 @@ Custom field UI visibility has no impact on API operation.
 * [#9536](https://github.com/netbox-community/netbox/issues/9536) - Track API token usage times
 * [#9536](https://github.com/netbox-community/netbox/issues/9536) - Track API token usage times
 * [#9582](https://github.com/netbox-community/netbox/issues/9582) - Enable assigning config contexts based on device location
 * [#9582](https://github.com/netbox-community/netbox/issues/9582) - Enable assigning config contexts based on device location
 
 
+### Bug Fixes
+
+* [#9728](https://github.com/netbox-community/netbox/issues/9728) - Fix validation when assigning a virtual machine to a device
+
 ### Plugins API
 ### Plugins API
 
 
 * [#9075](https://github.com/netbox-community/netbox/issues/9075) - Introduce `AbortRequest` exception for cleanly interrupting object mutations
 * [#9075](https://github.com/netbox-community/netbox/issues/9075) - Introduce `AbortRequest` exception for cleanly interrupting object mutations

+ 2 - 1
netbox/virtualization/forms/models.py

@@ -189,7 +189,8 @@ class VirtualMachineForm(TenancyForm, NetBoxModelForm):
         queryset=Device.objects.all(),
         queryset=Device.objects.all(),
         required=False,
         required=False,
         query_params={
         query_params={
-            'cluster_id': '$cluster'
+            'cluster_id': '$cluster',
+            'site_id': '$site',
         },
         },
         help_text="Optionally pin this VM to a specific host device within the cluster"
         help_text="Optionally pin this VM to a specific host device within the cluster"
     )
     )

+ 4 - 0
netbox/virtualization/models.py

@@ -349,6 +349,10 @@ class VirtualMachine(NetBoxModel, ConfigContextModel):
             })
             })
 
 
         # Validate assigned cluster device
         # Validate assigned cluster device
+        if self.device and not self.cluster:
+            raise ValidationError({
+                'device': f'Must specify a cluster when assigning a host device.'
+            })
         if self.device and self.device not in self.cluster.devices.all():
         if self.device and self.device not in self.cluster.devices.all():
             raise ValidationError({
             raise ValidationError({
                 'device': f'The selected device ({self.device} is not assigned to this cluster ({self.cluster}).'
                 'device': f'The selected device ({self.device} is not assigned to this cluster ({self.cluster}).'