blob: 39778418a5380c9dc10f520a46f36a7fbe9fef2a [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 viewsets
23from rest_framework import status
24from rest_framework.decorators import detail_route, list_route
25from rest_framework.views import APIView
26from core.models import *
27from django.forms import widgets
28from django.conf.urls import patterns, url
29from services.veg.models import VEGService
30from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
31from django.shortcuts import get_object_or_404
32from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
33from xos.exceptions import *
34import json
35import subprocess
36from django.views.decorators.csrf import ensure_csrf_cookie
37
38class VEGServiceForApi(VEGService):
39 class Meta:
40 proxy = True
41 app_label = "cord"
42
43 def __init__(self, *args, **kwargs):
44 super(VEGServiceForApi, self).__init__(*args, **kwargs)
45
46 def save(self, *args, **kwargs):
47 super(VEGServiceForApi, self).save(*args, **kwargs)
48
49 def __init__(self, *args, **kwargs):
50 super(VEGService, self).__init__(*args, **kwargs)
51
52class VEGServiceSerializer(PlusModelSerializer):
53 id = ReadOnlyField()
54 humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
55 wan_container_gateway_ip = serializers.CharField(required=False)
56 wan_container_gateway_mac = serializers.CharField(required=False)
57 dns_servers = serializers.CharField(required=False)
58 url_filter_kind = serializers.CharField(required=False)
59 node_label = serializers.CharField(required=False)
60
61 class Meta:
62 model = VEGServiceForApi
63 fields = ('humanReadableName',
64 'id',
65 'wan_container_gateway_ip',
66 'wan_container_gateway_mac',
67 'dns_servers',
68 'url_filter_kind',
69 'node_label')
70
71 def getHumanReadableName(self, obj):
72 return obj.__unicode__()
73
74# @ensure_csrf_cookie
75class VEGServiceViewSet(XOSViewSet):
76 base_name = "VEGservice"
77 method_name = None # use the api endpoint /api/service/veg/
78 method_kind = "viewset"
79 queryset = VEGService.get_service_objects().select_related().all()
80 serializer_class = VEGServiceSerializer
81
82 @classmethod
83 def get_urlpatterns(self, api_path="^"):
84 patterns = super(VEGServiceViewSet, self).get_urlpatterns(api_path=api_path)
85
86 return patterns
87
88 def list(self, request):
89 object_list = self.filter_queryset(self.get_queryset())
90
91 serializer = self.get_serializer(object_list, many=True)
92
93 return Response(serializer.data)
94