2016-08-03 14:24:09 -04:00
|
|
|
from circuits.models import Circuit
|
2017-11-15 12:54:49 -06:00
|
|
|
from dcim.models import Site, Rack, Device, RackReservation
|
2021-05-05 09:53:06 -04:00
|
|
|
from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF
|
2020-11-11 16:07:38 -05:00
|
|
|
from netbox.views import generic
|
2021-03-26 15:07:29 -04:00
|
|
|
from utilities.tables import paginate_table
|
2019-10-07 08:29:32 +02:00
|
|
|
from virtualization.models import VirtualMachine, Cluster
|
2021-04-29 16:38:56 -04:00
|
|
|
from . import filtersets, forms, tables
|
2017-11-07 11:08:23 -05:00
|
|
|
from .models import Tenant, TenantGroup
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tenant groups
|
|
|
|
#
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantGroupListView(generic.ObjectListView):
|
2020-03-11 20:20:04 -04:00
|
|
|
queryset = TenantGroup.objects.add_related_count(
|
|
|
|
TenantGroup.objects.all(),
|
|
|
|
Tenant,
|
|
|
|
'group',
|
|
|
|
'tenant_count',
|
|
|
|
cumulative=True
|
|
|
|
)
|
2016-07-26 14:58:37 -04:00
|
|
|
table = tables.TenantGroupTable
|
|
|
|
|
|
|
|
|
2021-03-26 15:07:29 -04:00
|
|
|
class TenantGroupView(generic.ObjectView):
|
|
|
|
queryset = TenantGroup.objects.all()
|
|
|
|
|
|
|
|
def get_extra_context(self, request, instance):
|
|
|
|
tenants = Tenant.objects.restrict(request.user, 'view').filter(
|
|
|
|
group=instance
|
|
|
|
)
|
|
|
|
|
|
|
|
tenants_table = tables.TenantTable(tenants)
|
|
|
|
tenants_table.columns.hide('group')
|
|
|
|
paginate_table(tenants_table, request)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'tenants_table': tenants_table,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantGroupEditView(generic.ObjectEditView):
|
2020-05-11 12:37:22 -04:00
|
|
|
queryset = TenantGroup.objects.all()
|
2017-09-12 13:54:44 -04:00
|
|
|
model_form = forms.TenantGroupForm
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantGroupDeleteView(generic.ObjectDeleteView):
|
2020-07-01 12:08:26 -04:00
|
|
|
queryset = TenantGroup.objects.all()
|
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantGroupBulkImportView(generic.BulkImportView):
|
2020-05-21 11:58:27 -04:00
|
|
|
queryset = TenantGroup.objects.all()
|
2017-10-09 15:09:40 -04:00
|
|
|
model_form = forms.TenantGroupCSVForm
|
|
|
|
table = tables.TenantGroupTable
|
|
|
|
|
|
|
|
|
2021-03-12 16:14:42 -05:00
|
|
|
class TenantGroupBulkEditView(generic.BulkEditView):
|
|
|
|
queryset = TenantGroup.objects.add_related_count(
|
|
|
|
TenantGroup.objects.all(),
|
|
|
|
Tenant,
|
|
|
|
'group',
|
|
|
|
'tenant_count',
|
|
|
|
cumulative=True
|
|
|
|
)
|
2021-04-29 16:38:56 -04:00
|
|
|
filterset = filtersets.TenantGroupFilterSet
|
2021-03-12 16:14:42 -05:00
|
|
|
table = tables.TenantGroupTable
|
|
|
|
form = forms.TenantGroupBulkEditForm
|
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantGroupBulkDeleteView(generic.BulkDeleteView):
|
2020-07-20 12:07:19 -04:00
|
|
|
queryset = TenantGroup.objects.add_related_count(
|
|
|
|
TenantGroup.objects.all(),
|
|
|
|
Tenant,
|
|
|
|
'group',
|
|
|
|
'tenant_count',
|
|
|
|
cumulative=True
|
|
|
|
)
|
2017-07-13 17:39:28 -04:00
|
|
|
table = tables.TenantGroupTable
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tenants
|
|
|
|
#
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantListView(generic.ObjectListView):
|
2020-10-30 16:52:40 -04:00
|
|
|
queryset = Tenant.objects.all()
|
2021-04-29 16:38:56 -04:00
|
|
|
filterset = filtersets.TenantFilterSet
|
2020-01-09 20:57:13 -05:00
|
|
|
filterset_form = forms.TenantFilterForm
|
2016-07-26 14:58:37 -04:00
|
|
|
table = tables.TenantTable
|
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantView(generic.ObjectView):
|
2020-05-21 15:39:07 -04:00
|
|
|
queryset = Tenant.objects.prefetch_related('group')
|
2017-05-18 17:00:57 -04:00
|
|
|
|
2020-11-19 15:59:11 -05:00
|
|
|
def get_extra_context(self, request, instance):
|
2017-05-18 17:00:57 -04:00
|
|
|
stats = {
|
2020-11-19 15:59:11 -05:00
|
|
|
'site_count': Site.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'rack_count': Rack.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'rackreservation_count': RackReservation.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'device_count': Device.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'vrf_count': VRF.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'prefix_count': Prefix.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
2021-05-05 09:53:06 -04:00
|
|
|
'aggregate_count': Aggregate.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
2020-11-19 15:59:11 -05:00
|
|
|
'ipaddress_count': IPAddress.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'vlan_count': VLAN.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'circuit_count': Circuit.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'virtualmachine_count': VirtualMachine.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
|
|
|
'cluster_count': Cluster.objects.restrict(request.user, 'view').filter(tenant=instance).count(),
|
2017-05-18 17:00:57 -04:00
|
|
|
}
|
|
|
|
|
2020-11-19 15:59:11 -05:00
|
|
|
return {
|
2017-05-18 17:00:57 -04:00
|
|
|
'stats': stats,
|
2020-11-19 15:59:11 -05:00
|
|
|
}
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantEditView(generic.ObjectEditView):
|
2020-05-11 12:37:22 -04:00
|
|
|
queryset = Tenant.objects.all()
|
2017-09-12 13:54:44 -04:00
|
|
|
model_form = forms.TenantForm
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantDeleteView(generic.ObjectDeleteView):
|
2020-05-11 12:47:01 -04:00
|
|
|
queryset = Tenant.objects.all()
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantBulkImportView(generic.BulkImportView):
|
2020-05-21 11:58:27 -04:00
|
|
|
queryset = Tenant.objects.all()
|
2017-05-31 17:40:11 -04:00
|
|
|
model_form = forms.TenantCSVForm
|
2016-07-26 14:58:37 -04:00
|
|
|
table = tables.TenantTable
|
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantBulkEditView(generic.BulkEditView):
|
2019-08-19 01:53:39 -04:00
|
|
|
queryset = Tenant.objects.prefetch_related('group')
|
2021-04-29 16:38:56 -04:00
|
|
|
filterset = filtersets.TenantFilterSet
|
2017-07-13 16:31:47 -04:00
|
|
|
table = tables.TenantTable
|
2016-07-26 14:58:37 -04:00
|
|
|
form = forms.TenantBulkEditForm
|
|
|
|
|
|
|
|
|
2020-11-11 16:07:38 -05:00
|
|
|
class TenantBulkDeleteView(generic.BulkDeleteView):
|
2019-08-19 01:53:39 -04:00
|
|
|
queryset = Tenant.objects.prefetch_related('group')
|
2021-04-29 16:38:56 -04:00
|
|
|
filterset = filtersets.TenantFilterSet
|
2017-07-13 17:39:28 -04:00
|
|
|
table = tables.TenantTable
|