return neutron network ids; add services_names endpoint for debugging
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index 7cc5cb7..2b450e0 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -168,16 +168,38 @@
# print "add instance", s
- def get_vtn_dependencies(self):
- provider_net_ids = []
+ def get_vtn_nets(self):
+ nets=[]
+ for slice in self.slices.all():
+ for ns in slice.networkslices.all():
+ if not ns.network:
+ continue
+ for cn in ns.network.controllernetworks.all():
+ if cn.net_id:
+ net = {"name": ns.network.name, "net_id": cn.net_id}
+ nets.append(net)
+ return nets
+
+ def get_vtn_dependencies_nets(self):
+ provider_nets = []
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
+ for net in tenant.provider_service.get_vtn_nets():
+ if not net in provider_nets:
+ provider_nets.append(net)
+ return provider_nets
+
+ def get_vtn_dependencies_ids(self):
+ return [x["net_id"] for x in self.get_vtn_dependencies_nets()]
+
+ def get_vtn_dependencies_names(self):
+ return [x["name"]+"_"+x["net_id"] for x in self.get_vtn_dependencies_nets()]
+
+ def get_vtn_ids(self):
+ return [x["net_id"] for x in self.get_vtn_nets()]
+
+ def get_vtn_names(self):
+ return [x["name"]+"_"+x["net_id"] for x in self.get_vtn_nets()]
class ServiceAttribute(PlCoreBase):
diff --git a/xos/core/xoslib/methods/vtn.py b/xos/core/xoslib/methods/vtn.py
index 9c96fc5..a912613 100644
--- a/xos/core/xoslib/methods/vtn.py
+++ b/xos/core/xoslib/methods/vtn.py
@@ -30,19 +30,34 @@
def get_urlpatterns(self):
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") )
return patterns
+ def get_services_names(self, request, pk=None):
+ result = {}
+ for service in Service.objects.all():
+ for id in service.get_vtn_names():
+ dependencies = service.get_vtn_dependencies_names()
+ if dependencies:
+ result[id] = dependencies
+ return Response(result)
+
def get_services(self, request, pk=None):
result = {}
for service in Service.objects.all():
- result[service.id] = service.get_vtn_dependencies()
+ for id in service.get_vtn_ids():
+ dependencies = service.get_vtn_dependencies_ids()
+ if dependencies:
+ result[id] = 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)
+ for xos_service in Service.objects.all():
+ if service in xos_service.get_vtn_ids():
+ return Response(xos_service.get_vtn_dependencies_ids())
+ raise DoesNotExist()
def list(self, request):
raise Exception("Not Implemented")