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
if self.virtual_chassis and self.vc_position is None:
raise ValidationError({

View File

@ -135,19 +135,28 @@ class Cluster(ContactsMixin, CachedScopeMixin, PrimaryModel):
def clean(self):
super().clean()
site = None
site = location = None
if self.scope_type:
scope_type = self.scope_type.model_class()
if scope_type == apps.get_model('dcim', 'site'):
site = self.scope
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 not self._state.adding and site:
if nonsite_devices := Device.objects.filter(cluster=self).exclude(site=site).count():
raise ValidationError({
'site': _(
"{count} devices are assigned as hosts for this cluster but are not in site {site}"
).format(count=nonsite_devices, site=site)
})
if not self._state.adding:
if site:
if nonsite_devices := Device.objects.filter(cluster=self).exclude(site=site).count():
raise ValidationError({
'scope': _(
"{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(
verbose_name=_('Status'),
)
site = tables.Column(
verbose_name=_('Site'),
linkify=True,
accessor='_site'
scope_type = columns.ContentTypeColumn(
verbose_name=_('Scope Type'),
)
scope = tables.Column(
verbose_name=_('Scope'),
linkify=True
)
device_count = columns.LinkedCountColumn(
viewname='dcim:device_list',
@ -98,7 +100,7 @@ class ClusterTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
class Meta(NetBoxTable.Meta):
model = Cluster
fields = (
'pk', 'id', 'name', 'type', 'group', 'status', 'tenant', 'tenant_group', 'site', 'description', 'comments',
'device_count', 'vm_count', 'contacts', 'tags', 'created', 'last_updated',
'pk', 'id', 'name', 'type', 'group', 'status', 'tenant', 'tenant_group', 'scope', 'scope_type', 'description',
'comments', 'device_count', 'vm_count', 'contacts', 'tags', 'created', 'last_updated',
)
default_columns = ('pk', 'name', 'type', 'group', 'status', 'tenant', 'site', 'device_count', 'vm_count')