vtn API
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index 953ea97..7cc5cb7 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -168,6 +168,18 @@
# print "add instance", s
+ def get_vtn_dependencies(self):
+ provider_net_ids = []
+ for tenant in self.subscribed_tenants.all():
+ if tenant.provider_service:
+ for slice in tenant.provider_service.slices.all():
+ for ns in slice.networkslices.all():
+ if ns.network:
+ if not (ns.network.id) in provider_net_ids:
+ provider_net_ids.append(ns.network_id)
+ return provider_net_ids
+
+
class ServiceAttribute(PlCoreBase):
name = models.CharField(help_text="Attribute Name", max_length=128)
value = StrippedCharField(help_text="Attribute Value", max_length=1024)
diff --git a/xos/core/xoslib/methods/cordsubscriber.py b/xos/core/xoslib/methods/cordsubscriber.py
index 297ac4a..3892014 100644
--- a/xos/core/xoslib/methods/cordsubscriber.py
+++ b/xos/core/xoslib/methods/cordsubscriber.py
@@ -11,7 +11,7 @@
from django.conf.urls import patterns, url
from cord.models import VOLTTenant, VBNGTenant, CordSubscriberRoot
from core.xoslib.objects.cordsubscriber import CordSubscriber
-from plus import PlusSerializerMixin
+from plus import PlusSerializerMixin, XOSViewSet
from django.shortcuts import get_object_or_404
from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
from xos.exceptions import *
@@ -158,30 +158,6 @@
subscriber.save()
return Response(serialize_user(subscriber,user))
-# this may be moved into plus.py...
-
-class XOSViewSet(viewsets.ModelViewSet):
- @classmethod
- def detail_url(self, pattern, viewdict, name):
- return url(r'^' + self.method_name + r'/(?P<pk>[a-zA-Z0-9\-]+)/' + pattern,
- self.as_view(viewdict),
- name=self.base_name+"_"+name)
-
- @classmethod
- def list_url(self, pattern, viewdict, name):
- return url(r'^' + self.method_name + r'/' + pattern,
- self.as_view(viewdict),
- name=self.base_name+"_"+name)
-
- @classmethod
- def get_urlpatterns(self):
- patterns = []
-
- patterns.append(url(r'^' + self.method_name + '/$', self.as_view({'get': 'list'}), name=self.base_name+'_list'))
- patterns.append(url(r'^' + self.method_name + '/(?P<pk>[a-zA-Z0-9\-]+)/$', self.as_view({'get': 'retrieve', 'put': 'update', 'post': 'update', 'delete': 'destroy', 'patch': 'partial_update'}), name=self.base_name+'_detail'))
-
- return patterns
-
#------------------------------------------------------------------------------
# The "new" API with many more REST endpoints.
# This is for integration with with the subscriber GUI
diff --git a/xos/core/xoslib/methods/plus.py b/xos/core/xoslib/methods/plus.py
index 280c468..294fba8 100644
--- a/xos/core/xoslib/methods/plus.py
+++ b/xos/core/xoslib/methods/plus.py
@@ -3,6 +3,8 @@
from rest_framework.response import Response
from rest_framework import status
from xos.apibase import XOSRetrieveUpdateDestroyAPIView, XOSListCreateAPIView
+from rest_framework import viewsets
+from django.conf.urls import patterns, url
""" PlusSerializerMixin
@@ -26,7 +28,24 @@
def getBackendHtml(self, obj):
return obj.getBackendHtml()
+class XOSViewSet(viewsets.ModelViewSet):
+ @classmethod
+ def detail_url(self, pattern, viewdict, name):
+ return url(r'^' + self.method_name + r'/(?P<pk>[a-zA-Z0-9\-]+)/' + pattern,
+ self.as_view(viewdict),
+ name=self.base_name+"_"+name)
+ @classmethod
+ def list_url(self, pattern, viewdict, name):
+ return url(r'^' + self.method_name + r'/' + pattern,
+ self.as_view(viewdict),
+ name=self.base_name+"_"+name)
+ @classmethod
+ def get_urlpatterns(self):
+ patterns = []
+ patterns.append(url(r'^' + self.method_name + '/$', self.as_view({'get': 'list'}), name=self.base_name+'_list'))
+ patterns.append(url(r'^' + self.method_name + '/(?P<pk>[a-zA-Z0-9\-]+)/$', self.as_view({'get': 'retrieve', 'put': 'update', 'post': 'update', 'delete': 'destroy', 'patch': 'partial_update'}), name=self.base_name+'_detail'))
+ return patterns
diff --git a/xos/core/xoslib/methods/vtn.py b/xos/core/xoslib/methods/vtn.py
new file mode 100644
index 0000000..9c96fc5
--- /dev/null
+++ b/xos/core/xoslib/methods/vtn.py
@@ -0,0 +1,49 @@
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from rest_framework import serializers
+from rest_framework import generics
+from rest_framework import viewsets
+from rest_framework.decorators import detail_route, list_route
+from rest_framework.views import APIView
+from core.models import *
+from django.forms import widgets
+from django.conf.urls import patterns, url
+from plus import PlusSerializerMixin, XOSViewSet
+from django.shortcuts import get_object_or_404
+from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
+from xos.exceptions import *
+import json
+import subprocess
+
+class VTNViewSet(XOSViewSet):
+ base_name = "vtn"
+ method_name = "rs/vtn"
+ method_kind = "viewset"
+
+ # 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
+
+ @classmethod
+ def get_urlpatterns(self):
+ patterns = []
+ patterns.append( self.list_url("services/$", {"get": "get_services"}, "services") )
+ patterns.append( self.list_url("services/(?P<service>[a-zA-Z0-9\-_]+)/$", {"get": "get_service"}, "get_service") )
+
+ return patterns
+
+ def get_services(self, request, pk=None):
+ result = {}
+ for service in Service.objects.all():
+ result[service.id] = service.get_vtn_dependencies()
+ return Response(result)
+
+ def get_service(self, request, pk=None, service=None):
+ result=Service.objects.get(pk = service).get_vtn_dependencies()
+ return Response(result)
+
+ def list(self, request):
+ raise Exception("Not Implemented")
+