Closes #4349: Drop support for embedded graphs

This commit is contained in:
Jeremy Stretch
2020-08-21 11:57:46 -04:00
parent ee34e28986
commit ec66e1a5c0
36 changed files with 33 additions and 595 deletions

View File

@@ -1,13 +1,8 @@
from django.db.models import Count
from django.shortcuts import get_object_or_404
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.routers import APIRootView
from dcim.models import Device
from extras.api.serializers import RenderedGraphSerializer
from extras.api.views import CustomFieldModelViewSet
from extras.models import Graph
from utilities.api import ModelViewSet
from utilities.utils import get_subquery
from virtualization import filters
@@ -91,13 +86,3 @@ class VMInterfaceViewSet(ModelViewSet):
)
serializer_class = serializers.VMInterfaceSerializer
filterset_class = filters.VMInterfaceFilterSet
@action(detail=True)
def graphs(self, request, pk):
"""
A convenience method for rendering graphs for a particular VM interface.
"""
vminterface = get_object_or_404(self.queryset, pk=pk)
queryset = Graph.objects.restrict(request.user).filter(type__model='vminterface')
serializer = RenderedGraphSerializer(queryset, many=True, context={'graphed_object': vminterface})
return Response(serializer.data)

View File

@@ -381,7 +381,7 @@ class VirtualMachine(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
# Interfaces
#
@extras_features('graphs', 'export_templates', 'webhooks')
@extras_features('export_templates', 'webhooks')
class VMInterface(BaseInterface):
virtual_machine = models.ForeignKey(
to='virtualization.VirtualMachine',

View File

@@ -1,10 +1,7 @@
from django.contrib.contenttypes.models import ContentType
from django.test import override_settings
from django.urls import reverse
from rest_framework import status
from dcim.choices import InterfaceModeChoices
from extras.models import Graph
from ipam.models import VLAN
from utilities.testing import APITestCase, APIViewTestCases
from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
@@ -244,25 +241,3 @@ class VMInterfaceTest(APIViewTestCases.APIViewTestCase):
'untagged_vlan': vlans[2].pk,
},
]
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
def test_get_vminterface_graphs(self):
"""
Test retrieval of Graphs assigned to VM interfaces.
"""
ct = ContentType.objects.get_for_model(VMInterface)
graphs = (
Graph(type=ct, name='Graph 1', source='http://example.com/graphs.py?interface={{ obj.name }}&foo=1'),
Graph(type=ct, name='Graph 2', source='http://example.com/graphs.py?interface={{ obj.name }}&foo=2'),
Graph(type=ct, name='Graph 3', source='http://example.com/graphs.py?interface={{ obj.name }}&foo=3'),
)
Graph.objects.bulk_create(graphs)
self.add_permissions('virtualization.view_vminterface')
url = reverse('virtualization-api:vminterface-graphs', kwargs={
'pk': VMInterface.objects.first().pk
})
response = self.client.get(url, **self.header)
self.assertEqual(len(response.data), 3)
self.assertEqual(response.data[0]['embed_url'], 'http://example.com/graphs.py?interface=Interface 1&foo=1')