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