mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Fixes #10517: Automatically inherit site assignment from cluster when creating a virtual machine
This commit is contained in:
parent
7feb86fe55
commit
7712b81ab9
@ -20,6 +20,7 @@
|
||||
* [#10480](https://github.com/netbox-community/netbox/issues/10480) - Cable trace SVG links should not force a new window
|
||||
* [#10491](https://github.com/netbox-community/netbox/issues/10491) - Clarify representation of blocking contact assignments during contact deletion
|
||||
* [#10513](https://github.com/netbox-community/netbox/issues/10513) - Disable the reassignment of a module to a new device
|
||||
* [#10517](https://github.com/netbox-community/netbox/issues/10517) - Automatically inherit site assignment from cluster when creating a virtual machine
|
||||
|
||||
---
|
||||
|
||||
|
@ -347,10 +347,12 @@ class VirtualMachine(NetBoxModel, ConfigContextModel):
|
||||
})
|
||||
|
||||
# Validate site for cluster & device
|
||||
if self.cluster and self.cluster.site != self.site:
|
||||
if self.cluster and self.site and self.cluster.site != self.site:
|
||||
raise ValidationError({
|
||||
'cluster': f'The selected cluster ({self.cluster} is not assigned to this site ({self.site}).'
|
||||
})
|
||||
elif self.cluster:
|
||||
self.site = self.cluster.site
|
||||
if self.device and self.device.site != self.site:
|
||||
raise ValidationError({
|
||||
'device': f'The selected device ({self.device} is not assigned to this site ({self.site}).'
|
||||
|
@ -68,6 +68,7 @@ class VirtualMachineTestCase(TestCase):
|
||||
with self.assertRaises(ValidationError):
|
||||
VirtualMachine(name='vm1', site=sites[0], cluster=clusters[1]).full_clean()
|
||||
|
||||
# VM with cluster site but no direct site should fail
|
||||
with self.assertRaises(ValidationError):
|
||||
VirtualMachine(name='vm1', site=None, cluster=clusters[0]).full_clean()
|
||||
# VM with cluster site but no direct site should have its site set automatically
|
||||
vm = VirtualMachine(name='vm1', site=None, cluster=clusters[0])
|
||||
vm.full_clean()
|
||||
self.assertEqual(vm.site, sites[0])
|
||||
|
Loading…
Reference in New Issue
Block a user