mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-30 04:16:24 -06:00
7699 review changes
This commit is contained in:
parent
c5005455f8
commit
effe9204af
@ -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({
|
||||
|
@ -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)
|
||||
})
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user