blob: 9415829f3da9caf559de30e9e0401dc9420802b1 [file] [log] [blame]
Andrea Campanellaedfdbca2017-02-01 17:33:47 -08001from 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.veg.models import VEGTenant, VEGService
10from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
11from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
12
13def get_default_veg_service():
14 VEG_services = VEGService.get_service_objects().all()
15 if VEG_services:
16 return VEG_services[0].id
17 return None
18
19class VEGTenantForAPI(VEGTenant):
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 VEGTenantSerializer(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 = VEGTenantForAPI
40 fields = ('humanReadableName', 'id', 'wan_container_ip', 'wan_container_mac', 'related' )
41
42 def getHumanReadableName(self, obj):
43 return obj.__unicode__()
44
45class VEGTenantViewSet(XOSViewSet):
46 base_name = "veg"
47 method_name = "veg"
48 method_kind = "viewset"
49 queryset = VEGTenantForAPI.get_tenant_objects().all()
50 serializer_class = VEGTenantSerializer
51
52 @classmethod
53 def get_urlpatterns(self, api_path="^"):
54 patterns = super(VEGTenantViewSet, self).get_urlpatterns(api_path=api_path)
55
56 return patterns
57
58
59
60
61
62