|
3 | 3 | from drf_spectacular.types import OpenApiTypes |
4 | 4 | from drf_spectacular.utils import extend_schema, OpenApiParameter |
5 | 5 | from rest_framework.decorators import action |
6 | | -from rest_framework.renderers import JSONRenderer |
7 | 6 | from rest_framework.response import Response |
8 | 7 | from rest_framework.routers import APIRootView |
9 | | -from rest_framework.status import HTTP_400_BAD_REQUEST |
10 | 8 | from rest_framework.viewsets import ViewSet |
11 | 9 |
|
12 | 10 | from circuits.models import Circuit |
13 | 11 | from dcim import filtersets |
14 | 12 | from dcim.constants import CABLE_TRACE_SVG_DEFAULT_WIDTH |
15 | 13 | from dcim.models import * |
16 | 14 | from dcim.svg import CableTraceSVG |
17 | | -from extras.api.mixins import ConfigContextQuerySetMixin, ConfigTemplateRenderMixin |
| 15 | +from extras.api.mixins import ConfigContextQuerySetMixin, RenderConfigMixin |
18 | 16 | from ipam.models import Prefix, VLAN |
19 | 17 | from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired |
20 | 18 | from netbox.api.metadata import ContentTypeMetadata |
21 | 19 | from netbox.api.pagination import StripCountAnnotationsPaginator |
22 | | -from netbox.api.renderers import TextRenderer |
23 | 20 | from netbox.api.viewsets import NetBoxModelViewSet, MPTTLockedMixin |
24 | 21 | from netbox.api.viewsets.mixins import SequentialBulkCreatesMixin |
25 | 22 | from netbox.constants import NESTED_SERIALIZER_PREFIX |
@@ -390,7 +387,7 @@ class PlatformViewSet(NetBoxModelViewSet): |
390 | 387 | class DeviceViewSet( |
391 | 388 | SequentialBulkCreatesMixin, |
392 | 389 | ConfigContextQuerySetMixin, |
393 | | - ConfigTemplateRenderMixin, |
| 390 | + RenderConfigMixin, |
394 | 391 | NetBoxModelViewSet |
395 | 392 | ): |
396 | 393 | queryset = Device.objects.prefetch_related( |
@@ -420,23 +417,6 @@ def get_serializer_class(self): |
420 | 417 |
|
421 | 418 | return serializers.DeviceWithConfigContextSerializer |
422 | 419 |
|
423 | | - @action(detail=True, methods=['post'], url_path='render-config', renderer_classes=[JSONRenderer, TextRenderer]) |
424 | | - def render_config(self, request, pk): |
425 | | - """ |
426 | | - Resolve and render the preferred ConfigTemplate for this Device. |
427 | | - """ |
428 | | - device = self.get_object() |
429 | | - configtemplate = device.get_config_template() |
430 | | - if not configtemplate: |
431 | | - return Response({'error': 'No config template found for this device.'}, status=HTTP_400_BAD_REQUEST) |
432 | | - |
433 | | - # Compile context data |
434 | | - context_data = device.get_config_context() |
435 | | - context_data.update(request.data) |
436 | | - context_data.update({'device': device}) |
437 | | - |
438 | | - return self.render_configtemplate(request, configtemplate, context_data) |
439 | | - |
440 | 420 |
|
441 | 421 | class VirtualDeviceContextViewSet(NetBoxModelViewSet): |
442 | 422 | queryset = VirtualDeviceContext.objects.prefetch_related( |
|
0 commit comments