2020-10-16 10:39:13 -04:00
|
|
|
import django_tables2 as tables
|
|
|
|
|
2021-04-08 10:08:50 -04:00
|
|
|
from dcim.models import Location, Region, Site, SiteGroup
|
2022-01-27 15:48:05 -05:00
|
|
|
from netbox.tables import NetBoxTable, columns
|
2021-03-04 16:07:55 -05:00
|
|
|
from tenancy.tables import TenantColumn
|
2022-01-10 11:17:40 -05:00
|
|
|
from .template_code import LOCATION_BUTTONS
|
2020-10-16 10:39:13 -04:00
|
|
|
|
|
|
|
__all__ = (
|
2021-04-08 10:08:50 -04:00
|
|
|
'LocationTable',
|
2020-10-16 10:39:13 -04:00
|
|
|
'RegionTable',
|
|
|
|
'SiteTable',
|
2021-03-08 13:28:53 -05:00
|
|
|
'SiteGroupTable',
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Regions
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class RegionTable(NetBoxTable):
|
2022-01-27 15:00:10 -05:00
|
|
|
name = columns.MPTTColumn(
|
2021-03-26 15:07:29 -04:00
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
site_count = columns.LinkedCountColumn(
|
2021-04-06 09:42:36 -04:00
|
|
|
viewname='dcim:site_list',
|
|
|
|
url_params={'region_id': 'pk'},
|
2020-10-16 10:39:13 -04:00
|
|
|
verbose_name='Sites'
|
|
|
|
)
|
2022-03-09 17:35:25 +00:00
|
|
|
contacts = tables.ManyToManyColumn(
|
|
|
|
linkify_item=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='dcim:region_list'
|
|
|
|
)
|
2020-10-16 10:39:13 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2020-10-16 10:39:13 -04:00
|
|
|
model = Region
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
2022-03-18 13:17:11 -04:00
|
|
|
'pk', 'id', 'name', 'slug', 'site_count', 'description', 'contacts', 'tags', 'created', 'last_updated',
|
|
|
|
'actions',
|
2022-01-17 11:12:54 -05:00
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'site_count', 'description')
|
2020-10-16 10:39:13 -04:00
|
|
|
|
|
|
|
|
2021-03-08 13:28:53 -05:00
|
|
|
#
|
|
|
|
# Site groups
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class SiteGroupTable(NetBoxTable):
|
2022-01-27 15:00:10 -05:00
|
|
|
name = columns.MPTTColumn(
|
2021-03-26 15:07:29 -04:00
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
site_count = columns.LinkedCountColumn(
|
2021-04-06 09:42:36 -04:00
|
|
|
viewname='dcim:site_list',
|
|
|
|
url_params={'group_id': 'pk'},
|
2021-03-08 13:28:53 -05:00
|
|
|
verbose_name='Sites'
|
|
|
|
)
|
2022-03-09 17:35:25 +00:00
|
|
|
contacts = tables.ManyToManyColumn(
|
|
|
|
linkify_item=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='dcim:sitegroup_list'
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2021-03-08 13:28:53 -05:00
|
|
|
model = SiteGroup
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
2022-03-18 13:17:11 -04:00
|
|
|
'pk', 'id', 'name', 'slug', 'site_count', 'description', 'contacts', 'tags', 'created', 'last_updated',
|
|
|
|
'actions',
|
2022-01-17 11:12:54 -05:00
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'site_count', 'description')
|
2021-03-08 13:28:53 -05:00
|
|
|
|
|
|
|
|
2020-10-16 10:39:13 -04:00
|
|
|
#
|
|
|
|
# Sites
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class SiteTable(NetBoxTable):
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
status = columns.ChoiceFieldColumn()
|
2020-10-16 10:39:13 -04:00
|
|
|
region = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-03-08 13:28:53 -05:00
|
|
|
group = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2022-03-30 17:17:36 -04:00
|
|
|
asns = tables.ManyToManyColumn(
|
|
|
|
linkify_item=True,
|
|
|
|
verbose_name='ASNs'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
asn_count = columns.LinkedCountColumn(
|
2022-02-02 09:18:50 -05:00
|
|
|
accessor=tables.A('asns__count'),
|
2021-10-24 23:42:47 -05:00
|
|
|
viewname='ipam:asn_list',
|
|
|
|
url_params={'site_id': 'pk'},
|
2022-03-04 13:20:17 -05:00
|
|
|
verbose_name='ASN Count'
|
|
|
|
)
|
2021-03-04 16:07:55 -05:00
|
|
|
tenant = TenantColumn()
|
2022-01-27 15:00:10 -05:00
|
|
|
comments = columns.MarkdownColumn()
|
2022-03-09 17:35:25 +00:00
|
|
|
contacts = tables.ManyToManyColumn(
|
|
|
|
linkify_item=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2020-10-16 10:39:13 -04:00
|
|
|
url_name='dcim:site_list'
|
|
|
|
)
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2020-10-16 10:39:13 -04:00
|
|
|
model = Site
|
|
|
|
fields = (
|
2022-03-04 13:20:17 -05:00
|
|
|
'pk', 'id', 'name', 'slug', 'status', 'facility', 'region', 'group', 'tenant', 'asns', 'asn_count',
|
2022-03-07 10:55:30 -05:00
|
|
|
'time_zone', 'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'comments',
|
2022-03-18 13:17:11 -04:00
|
|
|
'contacts', 'tags', 'created', 'last_updated', 'actions',
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2021-11-04 16:29:43 -04:00
|
|
|
default_columns = ('pk', 'name', 'status', 'facility', 'region', 'group', 'tenant', 'description')
|
2021-04-08 10:08:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Locations
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class LocationTable(NetBoxTable):
|
2022-01-27 15:00:10 -05:00
|
|
|
name = columns.MPTTColumn(
|
2021-04-08 10:08:50 -04:00
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
site = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-10-07 15:46:21 -04:00
|
|
|
tenant = TenantColumn()
|
2022-01-27 15:00:10 -05:00
|
|
|
rack_count = columns.LinkedCountColumn(
|
2021-04-26 15:28:35 -04:00
|
|
|
viewname='dcim:rack_list',
|
|
|
|
url_params={'location_id': 'pk'},
|
2021-04-08 10:08:50 -04:00
|
|
|
verbose_name='Racks'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
device_count = columns.LinkedCountColumn(
|
2021-04-26 15:28:35 -04:00
|
|
|
viewname='dcim:device_list',
|
|
|
|
url_params={'location_id': 'pk'},
|
2021-04-08 10:08:50 -04:00
|
|
|
verbose_name='Devices'
|
|
|
|
)
|
2022-03-09 17:35:25 +00:00
|
|
|
contacts = tables.ManyToManyColumn(
|
|
|
|
linkify_item=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='dcim:location_list'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
actions = columns.ActionsColumn(
|
2022-01-10 11:17:40 -05:00
|
|
|
extra_buttons=LOCATION_BUTTONS
|
2021-04-08 10:08:50 -04:00
|
|
|
)
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2021-04-08 10:08:50 -04:00
|
|
|
model = Location
|
2021-10-21 10:51:02 -04:00
|
|
|
fields = (
|
2022-03-09 17:55:45 +00:00
|
|
|
'pk', 'id', 'name', 'site', 'tenant', 'rack_count', 'device_count', 'description', 'slug', 'contacts',
|
2022-03-09 17:35:25 +00:00
|
|
|
'tags', 'actions', 'created', 'last_updated',
|
2021-10-21 10:51:02 -04:00
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'site', 'tenant', 'rack_count', 'device_count', 'description')
|