add VTN API rest endpoint to new api
diff --git a/xos/api/service/vtn.py b/xos/api/service/vtn.py
index 970689f..6b02616 100644
--- a/xos/api/service/vtn.py
+++ b/xos/api/service/vtn.py
@@ -7,6 +7,7 @@
from rest_framework.decorators import detail_route, list_route
from rest_framework.views import APIView
from core.models import *
+from services.vtn.models import VTNService
from django.forms import widgets
from django.conf.urls import patterns, url
from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
@@ -16,6 +17,30 @@
import json
import subprocess
+class VTNServiceSerializer(PlusModelSerializer):
+ id = ReadOnlyField()
+
+ privateGatewayMac = serializers.CharField(required=False)
+ localManagementIp = serializers.CharField(required=False)
+ ovsdbPort = serializers.IntegerField(required=False)
+ sshPort = serializers.IntegerField(required=False)
+ sshUser = serializers.CharField(required=False)
+ sshKeyFile = serializers.CharField(required=False)
+ mgmtSubnetBits = serializers.IntegerField(required=False)
+ xosEndpoint = serializers.CharField(required=False)
+ xosUser = serializers.CharField(required=False)
+ xosPassword = serializers.CharField(required=False)
+
+
+ humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
+ class Meta:
+ model = VTNService
+ fields = ('humanReadableName', 'id', 'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile',
+ 'mgmtSubnetBits', 'xosEndpoint', 'xosUser', 'xosPassword')
+
+ def getHumanReadableName(self, obj):
+ return obj.__unicode__()
+
class VTNViewSet(XOSViewSet):
base_name = "vtn"
method_name = "vtn"
@@ -23,16 +48,24 @@
# these are just because ViewSet needs some queryset and model, even if we don't use the
# default endpoints
- queryset = Service.objects.none() # CordSubscriber.get_tenant_objects().select_related().all()
- model = Service
+ queryset = VTNService.get_service_objects().all()
+ model = VTNService
+ serializer_class = VTNServiceSerializer
@classmethod
def get_urlpatterns(self, api_path="^"):
- patterns = [] # super(VTNViewSet, self).get_urlpatterns(api_path=api_path)
+ patterns = []
- patterns.append( self.list_url("services/$", {"get": "get_services"}, "services") )
- patterns.append( self.list_url("services_names/$", {"get": "get_services_names"}, "services") )
- patterns.append( self.list_url("services/(?P<service>[a-zA-Z0-9\-_]+)/$", {"get": "get_service"}, "get_service") )
+ patterns.append( self.detail_url("services/$", {"get": "get_services"}, "services") )
+ patterns.append( self.detail_url("services_names/$", {"get": "get_services_names"}, "services") )
+ patterns.append( self.detail_url("services/(?P<service>[a-zA-Z0-9\-_]+)/$", {"get": "get_service"}, "get_service") )
+
+ # Not as RESTful as it could be, but maintain these endpoints for compability
+ patterns.append( self.list_url("services/$", {"get": "get_services"}, "rootvtn_services") )
+ patterns.append( self.list_url("services_names/$", {"get": "get_services_names"}, "rootvtn_services") )
+ patterns.append( self.list_url("services/(?P<service>[a-zA-Z0-9\-_]+)/$", {"get": "get_service"}, "rootvtn_get_service") )
+
+ patterns = patterns + super(VTNViewSet,self).get_urlpatterns(api_path)
return patterns
@@ -58,8 +91,6 @@
for xos_service in Service.objects.all():
if service in xos_service.get_vtn_src_ids():
return Response(xos_service.get_vtn_dependencies_ids())
- raise DoesNotExist()
+ return Response([])
- def list(self, request):
- raise Exception("Not Implemented")