7699 review changes

This commit is contained in:
Arthur Hanson 2024-10-28 09:08:17 -07:00
parent c5005455f8
commit effe9204af
3 changed files with 33 additions and 15 deletions

View File

@ -965,6 +965,13 @@ class Device(
) )
}) })
if self.cluster and self.cluster._location is not None and self.cluster._location != self.location:
raise ValidationError({
'cluster': _("The assigned cluster belongs to a different location ({location})").format(
site=self.cluster._location
)
})
# Validate virtual chassis assignment # Validate virtual chassis assignment
if self.virtual_chassis and self.vc_position is None: if self.virtual_chassis and self.vc_position is None:
raise ValidationError({ raise ValidationError({

View File

@ -135,19 +135,28 @@ class Cluster(ContactsMixin, CachedScopeMixin, PrimaryModel):
def clean(self): def clean(self):
super().clean() super().clean()
site = None site = location = None
if self.scope_type: if self.scope_type:
scope_type = self.scope_type.model_class() scope_type = self.scope_type.model_class()
if scope_type == apps.get_model('dcim', 'site'): if scope_type == apps.get_model('dcim', 'site'):
site = self.scope site = self.scope
elif scope_type == apps.get_model('dcim', 'location'): elif scope_type == apps.get_model('dcim', 'location'):
site = self.scope.site location = self.scope
site = location.site
# If the Cluster is assigned to a Site, verify that all host Devices belong to that Site. # If the Cluster is assigned to a Site, verify that all host Devices belong to that Site.
if not self._state.adding and site: if not self._state.adding:
if nonsite_devices := Device.objects.filter(cluster=self).exclude(site=site).count(): if site:
raise ValidationError({ if nonsite_devices := Device.objects.filter(cluster=self).exclude(site=site).count():
'site': _( raise ValidationError({
"{count} devices are assigned as hosts for this cluster but are not in site {site}" 'scope': _(
).format(count=nonsite_devices, site=site) "{count} devices are assigned as hosts for this cluster but are not in site {site}"
}) ).format(count=nonsite_devices, site=site)
})
if location:
if nonlocation_devices := Device.objects.filter(cluster=self).exclude(location=location).count():
raise ValidationError({
'scope': _(
"{count} devices are assigned as hosts for this cluster but are not in location {location}"
).format(count=nonlocation_devices, location=location)
})

View File

@ -73,10 +73,12 @@ class ClusterTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
status = columns.ChoiceFieldColumn( status = columns.ChoiceFieldColumn(
verbose_name=_('Status'), verbose_name=_('Status'),
) )
site = tables.Column( scope_type = columns.ContentTypeColumn(
verbose_name=_('Site'), verbose_name=_('Scope Type'),
linkify=True, )
accessor='_site' scope = tables.Column(
verbose_name=_('Scope'),
linkify=True
) )
device_count = columns.LinkedCountColumn( device_count = columns.LinkedCountColumn(
viewname='dcim:device_list', viewname='dcim:device_list',
@ -98,7 +100,7 @@ class ClusterTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
class Meta(NetBoxTable.Meta): class Meta(NetBoxTable.Meta):
model = Cluster model = Cluster
fields = ( fields = (
'pk', 'id', 'name', 'type', 'group', 'status', 'tenant', 'tenant_group', 'site', 'description', 'comments', 'pk', 'id', 'name', 'type', 'group', 'status', 'tenant', 'tenant_group', 'scope', 'scope_type', 'description',
'device_count', 'vm_count', 'contacts', 'tags', 'created', 'last_updated', 'comments', 'device_count', 'vm_count', 'contacts', 'tags', 'created', 'last_updated',
) )
default_columns = ('pk', 'name', 'type', 'group', 'status', 'tenant', 'site', 'device_count', 'vm_count') default_columns = ('pk', 'name', 'type', 'group', 'status', 'tenant', 'site', 'device_count', 'vm_count')