mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #9728: Fix validation when assigning a virtual machine to a device
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
@@ -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}).'
|
||||
|
Reference in New Issue
Block a user