-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v3.3.4
Python version
3.8
Steps to Reproduce
- Create sites DC1 and DC2
- Create a cluster named Stretched (type doesn't matter). Do not assign it to a Site.
- Create two devices, device_dc1, device_dc2 and assign them to site DC1 and DC2
- Add device_dc1, device_dc2 to your cluster Stretched.
- Create a virtual machine vm_dc1
- Assign it to the cluster Stretched, and try to pin it to device_dc1
Expected Behavior
To be allowed to pin the virtual machine to a specific device in the cluster.
Observed Behavior
You get an error message saying "The selected device (device_in_ds1 is not assigned to this site (None).". To get it to work I have to assign the cluster to the site DC1, but I can't do that either because the cluster contains devices not in DC1. If all devices in the cluster is the same Site, and the Cluster is assigned a Site the functionality works as expected.
I thought about raising this as an FR, but I think the fact that I can create a cluster and have devices in multiple sites assigned to the cluster I should also be able to pin a virtual machine to these devices.
I believe the logic for this is in the below code, but I'm not quite sure what should change.
netbox/netbox/virtualization/models.py
Lines 349 to 359 in 53f5f46
| # Validate site for cluster & device | |
| 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}).' | |
| }) |