blob: a2dd29a29ac67d90e1bd08ca620900c757975be6 [file] [log] [blame]
Matteo Scandolo6288d5a2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Andrea Campanellaedfdbca2017-02-01 17:33:47 -080017from rest_framework.decorators import api_view
18from rest_framework.response import Response
19from rest_framework.reverse import reverse
20from rest_framework import serializers
21from rest_framework import generics
22from rest_framework import status
23from core.models import *
24from django.forms import widgets
25from services.veg.models import VEGTenant, VEGService
26from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
27from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
28
29def get_default_veg_service():
30 VEG_services = VEGService.get_service_objects().all()
31 if VEG_services:
32 return VEG_services[0].id
33 return None
34
35class VEGTenantForAPI(VEGTenant):
36 class Meta:
37 proxy = True
38 app_label = "cord"
39
40 @property
41 def related(self):
42 related = {}
43 if self.instance:
44 related["instance_id"] = self.instance.id
45 return related
46
47class VEGTenantSerializer(PlusModelSerializer):
48 id = ReadOnlyField()
49 wan_container_ip = serializers.CharField()
50 wan_container_mac = ReadOnlyField()
51 related = serializers.DictField(required=False)
52
53 humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
54 class Meta:
55 model = VEGTenantForAPI
56 fields = ('humanReadableName', 'id', 'wan_container_ip', 'wan_container_mac', 'related' )
57
58 def getHumanReadableName(self, obj):
59 return obj.__unicode__()
60
61class VEGTenantViewSet(XOSViewSet):
62 base_name = "veg"
63 method_name = "veg"
64 method_kind = "viewset"
65 queryset = VEGTenantForAPI.get_tenant_objects().all()
66 serializer_class = VEGTenantSerializer
67
68 @classmethod
69 def get_urlpatterns(self, api_path="^"):
70 patterns = super(VEGTenantViewSet, self).get_urlpatterns(api_path=api_path)
71
72 return patterns
73
74
75
76
77
78