From 1bb2656c4209bdb7e253c88b44b64688344652e1 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Thu, 10 Oct 2024 11:29:04 -0700 Subject: [PATCH 1/3] 17614 Disallow removal of virtual chassis from device if set as master --- netbox/dcim/models/devices.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index a2b78957e40..554c8390b19 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -983,6 +983,13 @@ def clean(self): 'vc_position': _("A device assigned to a virtual chassis must have its position defined.") }) + if hasattr(self, 'vc_master_for') and self.vc_master_for and self.vc_master_for != self.virtual_chassis: + raise ValidationError({ + 'virtual_chassis': _("Cannot change to a different virtual chassis when assigned as a master. Remove it as the master of {master} first.").format( + master=self.vc_master_for + ) + }) + def _instantiate_components(self, queryset, bulk_create=True): """ Instantiate components for the device from the specified component templates. From 3f50b4f412b90b74263360860c859d25080efa15 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Fri, 11 Oct 2024 10:50:11 -0700 Subject: [PATCH 2/3] 17614 review changes --- netbox/dcim/models/devices.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 554c8390b19..90b3e4e8830 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -983,10 +983,10 @@ def clean(self): 'vc_position': _("A device assigned to a virtual chassis must have its position defined.") }) - if hasattr(self, 'vc_master_for') and self.vc_master_for and self.vc_master_for != self.virtual_chassis: + if vc_master_for := getattr(self, 'vc_master_for', None) != self.virtual_chassis: raise ValidationError({ - 'virtual_chassis': _("Cannot change to a different virtual chassis when assigned as a master. Remove it as the master of {master} first.").format( - master=self.vc_master_for + 'virtual_chassis': _('Device cannot be removed from virtual chassis {virtual_chassis} because it is currently designated as its master.').format( + virtual_chassis=self.vc_master_for ) }) From 7f91752092a0ce2bfac7b94ac29610dbae9d8e2c Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Fri, 11 Oct 2024 11:03:08 -0700 Subject: [PATCH 3/3] 17614 review changes --- netbox/dcim/models/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 90b3e4e8830..0f11cb5f30a 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -983,7 +983,7 @@ def clean(self): 'vc_position': _("A device assigned to a virtual chassis must have its position defined.") }) - if vc_master_for := getattr(self, 'vc_master_for', None) != self.virtual_chassis: + if hasattr(self, 'vc_master_for') and self.vc_master_for and self.vc_master_for != self.virtual_chassis: raise ValidationError({ 'virtual_chassis': _('Device cannot be removed from virtual chassis {virtual_chassis} because it is currently designated as its master.').format( virtual_chassis=self.vc_master_for