From 024e7d86510adcbe8a948640c052fb1c4059223a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 15 Jul 2022 10:19:56 -0400 Subject: [PATCH] Fixes #9728: Fix validation when assigning a virtual machine to a device --- docs/release-notes/version-3.3.md | 6 +++++- netbox/virtualization/forms/models.py | 3 ++- netbox/virtualization/models.py | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-3.3.md b/docs/release-notes/version-3.3.md index 5fc11960e..b0bcaaa63 100644 --- a/docs/release-notes/version-3.3.md +++ b/docs/release-notes/version-3.3.md @@ -1,6 +1,6 @@ # NetBox v3.3 -## v3.3-beta1 (2022-07-14) +## v3.3.0 (FUTURE) ### 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 * [#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 * [#9075](https://github.com/netbox-community/netbox/issues/9075) - Introduce `AbortRequest` exception for cleanly interrupting object mutations diff --git a/netbox/virtualization/forms/models.py b/netbox/virtualization/forms/models.py index a60d15281..723c19332 100644 --- a/netbox/virtualization/forms/models.py +++ b/netbox/virtualization/forms/models.py @@ -189,7 +189,8 @@ class VirtualMachineForm(TenancyForm, NetBoxModelForm): queryset=Device.objects.all(), required=False, 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" ) diff --git a/netbox/virtualization/models.py b/netbox/virtualization/models.py index 98321976f..f07b176e7 100644 --- a/netbox/virtualization/models.py +++ b/netbox/virtualization/models.py @@ -349,6 +349,10 @@ class VirtualMachine(NetBoxModel, ConfigContextModel): }) # 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(): raise ValidationError({ 'device': f'The selected device ({self.device} is not assigned to this cluster ({self.cluster}).'