Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #15428 - Show all devices with configuration template attached #15822

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions netbox/extras/tables/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,35 @@ class ConfigTemplateTable(NetBoxTable):
tags = columns.TagColumn(
url_name='extras:configtemplate_list'
)
role_count = columns.LinkedCountColumn(
viewname='dcim:devicerole_list',
url_params={'config_template_id': 'pk'},
verbose_name=_('Device Roles')
)
platform_count = columns.LinkedCountColumn(
viewname='dcim:platform_list',
url_params={'config_template_id': 'pk'},
verbose_name=_('Platforms')
)
device_count = columns.LinkedCountColumn(
viewname='dcim:device_list',
url_params={'config_template_id': 'pk'},
verbose_name=_('Devices')
)
vm_count = columns.LinkedCountColumn(
viewname='virtualization:virtualmachine_list',
url_params={'config_template_id': 'pk'},
verbose_name=_('Virtual Machines')
)

class Meta(NetBoxTable.Meta):
model = ConfigTemplate
fields = (
'pk', 'id', 'name', 'description', 'data_source', 'data_file', 'data_synced', 'created', 'last_updated',
'tags',
'pk', 'id', 'name', 'description', 'data_source', 'data_file', 'data_synced', 'role_count',
'platform_count', 'device_count', 'vm_count', 'created', 'last_updated', 'tags',
)
default_columns = (
'pk', 'name', 'description', 'is_synced',
'pk', 'name', 'description', 'is_synced', 'device_count', 'vm_count',
)


Expand Down
9 changes: 8 additions & 1 deletion netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from core.forms import ManagedFileForm
from core.models import Job
from core.tables import JobTable
from dcim.models import Device, DeviceRole, Platform
from extras.dashboard.forms import DashboardWidgetAddForm, DashboardWidgetForm
from extras.dashboard.utils import get_widget_class
from netbox.constants import DEFAULT_ACTION_PERMISSIONS
Expand All @@ -24,6 +25,7 @@
from utilities.templatetags.builtins.filters import render_markdown
from utilities.utils import copy_safe_request, count_related, get_viewname, normalize_querydict, shallow_compare_dict
from utilities.views import ContentTypePermissionRequiredMixin, register_model_view
from virtualization.models import VirtualMachine
from . import filtersets, forms, tables
from .forms.reports import ReportForm
from .models import *
Expand Down Expand Up @@ -624,7 +626,12 @@ def get_extra_context(self, request, instance):
#

class ConfigTemplateListView(generic.ObjectListView):
queryset = ConfigTemplate.objects.all()
queryset = ConfigTemplate.objects.annotate(
device_count=count_related(Device, 'config_template'),
vm_count=count_related(VirtualMachine, 'config_template'),
role_count=count_related(DeviceRole, 'config_template'),
platform_count=count_related(Platform, 'config_template'),
)
filterset = filtersets.ConfigTemplateFilterSet
filterset_form = forms.ConfigTemplateFilterForm
table = tables.ConfigTemplateTable
Expand Down
Loading