blob: c6a42478a764381a2d3b15ef3fa930a365c32816 [file] [log] [blame]
Scott Baker761e1062016-06-20 17:18:17 -07001from rest_framework.decorators import api_view
2from rest_framework.response import Response
3from rest_framework.reverse import reverse
4from rest_framework import serializers
5from rest_framework import generics
6from rest_framework import status
7from core.models import *
8from django.forms import widgets
9from services.vsg.models import VSGTenant, VSGService
10from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
11from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
12
13def get_default_vsg_service():
14 vsg_services = VSGService.get_service_objects().all()
15 if vsg_services:
16 return vsg_services[0].id
17 return None
18
19class VSGTenantForAPI(VSGTenant):
20 class Meta:
21 proxy = True
22 app_label = "cord"
23
24 @property
25 def related(self):
26 related = {}
27 if self.instance:
28 related["instance_id"] = self.instance.id
29 return related
30
31class VSGTenantSerializer(PlusModelSerializer):
32 id = ReadOnlyField()
33 wan_container_ip = serializers.CharField()
34 wan_container_mac = ReadOnlyField()
35 related = serializers.DictField(required=False)
36
37 humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
38 class Meta:
39 model = VSGTenantForAPI
40 fields = ('humanReadableName', 'id', 'wan_container_ip', 'wan_container_mac', 'related' )
41
42 def getHumanReadableName(self, obj):
43 return obj.__unicode__()
44
45class VSGTenantViewSet(XOSViewSet):
46 base_name = "vsg"
47 method_name = "vsg"
48 method_kind = "viewset"
49 queryset = VSGTenantForAPI.get_tenant_objects().all()
50 serializer_class = VSGTenantSerializer
51
52 @classmethod
53 def get_urlpatterns(self, api_path="^"):
54 patterns = super(VSGTenantViewSet, self).get_urlpatterns(api_path=api_path)
55
56 return patterns
57
58
59
60
61
62