diff options
-rw-r--r-- | lcm/ns/ns_get.py | 23 | ||||
-rw-r--r-- | lcm/ns/tests/test_ns_create.py | 2 | ||||
-rw-r--r-- | lcm/ns/tests/test_ns_get.py | 37 | ||||
-rw-r--r-- | lcm/ns/views.py | 12 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/vnfdmodel.py | 37 | ||||
-rw-r--r-- | lcm/swagger/vfc.nslcm.swagger.json | 40 |
6 files changed, 131 insertions, 20 deletions
diff --git a/lcm/ns/ns_get.py b/lcm/ns/ns_get.py index 15f20e15..0bd39559 100644 --- a/lcm/ns/ns_get.py +++ b/lcm/ns/ns_get.py @@ -22,21 +22,20 @@ logger = logging.getLogger(__name__) class GetNSInfoService(object): - def __init__(self, ns_inst_id=None): - self.ns_inst_id = ns_inst_id + def __init__(self, nsfilter=None): + self.ns_filter=nsfilter def get_ns_info(self): - try: - if self.ns_inst_id: - return self.get_single_ns_info(self.ns_inst_id) - else: - return self.get_total_ns_info() - except: - logger.error(traceback.format_exc()) - return None if self.ns_inst_id else [] + if self.ns_filter: + if ("ns_inst_id" in self.ns_filter): + ns_inst_id = self.ns_filter["ns_inst_id"] + ns_inst_infos = NSInstModel.objects.filter(id=ns_inst_id) + if ("csarId" in self.ns_filter): + csar_id = self.ns_filter["csarId"] + ns_inst_infos = NSInstModel.objects.filter(nsd_id=csar_id) + else: + ns_inst_infos = NSInstModel.objects.all() - def get_total_ns_info(self): - ns_inst_infos = NSInstModel.objects.all() ns_info_list = [] for info in ns_inst_infos: ret = self.get_single_ns_info(info.id) diff --git a/lcm/ns/tests/test_ns_create.py b/lcm/ns/tests/test_ns_create.py index 0f230565..a1b836eb 100644 --- a/lcm/ns/tests/test_ns_create.py +++ b/lcm/ns/tests/test_ns_create.py @@ -1,4 +1,4 @@ -# Copyright 2016 ZTE Corporation. +# Copyright 2017 ZTE Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lcm/ns/tests/test_ns_get.py b/lcm/ns/tests/test_ns_get.py new file mode 100644 index 00000000..9da1ab3e --- /dev/null +++ b/lcm/ns/tests/test_ns_get.py @@ -0,0 +1,37 @@ +# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import uuid
+
+from django.test import TestCase, Client
+from rest_framework import status
+
+from lcm.pub.database.models import NSInstModel
+
+
+class TestNsQuery(TestCase):
+ def setUp(self):
+ self.client = Client()
+ self.nsd_id = str(uuid.uuid4())
+ self.ns_package_id = str(uuid.uuid4())
+ NSInstModel(id=1, nsd_id=1, name='test01').save()
+ NSInstModel(id=2, nsd_id=1, name='test02').save()
+
+ def test_query_ns_by_csarId(self):
+ response = self.client.get("/api/nslcm/v1/ns?csarId=1")
+ self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+
+ def test_query_ns_by_nsinstance_id(self):
+ response = self.client.get("/api/nslcm/v1/ns/1")
+ self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
\ No newline at end of file diff --git a/lcm/ns/views.py b/lcm/ns/views.py index 8fa4ba77..9a25027e 100644 --- a/lcm/ns/views.py +++ b/lcm/ns/views.py @@ -38,7 +38,14 @@ logger = logging.getLogger(__name__) class CreateNSView(APIView): def get(self, request): logger.debug("CreateNSView::get") - ret = GetNSInfoService().get_ns_info() + filter=None + csarId = ignore_case_get(request.META, 'csarId') + if csarId: + filter ={ + "csarId":csarId + } + + ret = GetNSInfoService(filter).get_ns_info() logger.debug("CreateNSView::get::ret=%s", ret) return Response(data=ret, status=status.HTTP_200_OK) @@ -96,7 +103,8 @@ class NSHealView(APIView): class NSDetailView(APIView): def get(self, request, ns_instance_id): logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id) - ret = GetNSInfoService(ns_instance_id).get_ns_info() + ns_filter ={"ns_inst_id":ns_instance_id} + ret = GetNSInfoService(ns_filter).get_ns_info() if not ret: return Response(status=status.HTTP_404_NOT_FOUND) logger.debug("Leave NSDetailView::get::ret=%s", ret) diff --git a/lcm/pub/utils/toscaparser/vnfdmodel.py b/lcm/pub/utils/toscaparser/vnfdmodel.py index 166690b8..443bdb82 100644 --- a/lcm/pub/utils/toscaparser/vnfdmodel.py +++ b/lcm/pub/utils/toscaparser/vnfdmodel.py @@ -39,6 +39,10 @@ class EtsiVnfdInfoModel(EtsiNsdInfoModel): self.vdus = self._get_all_vdu(nodeTemplates) self.vls = self.get_all_vl(nodeTemplates) self.cps = self.get_all_cp(nodeTemplates) + self.plugins = self.get_all_plugin(nodeTemplates) + self.routers = self.get_all_router(nodeTemplates) + self.server_groups = self.get_all_server_group(tosca.topology_template.groups) + self.element_groups = self._get_all_element_group(tosca.topology_template.groups) def _get_all_services(self, nodeTemplates): @@ -251,3 +255,36 @@ class EtsiVnfdInfoModel(EtsiNsdInfoModel): cp['vls'] = vls cps.append(cp) return cps + + def get_all_plugin(self, node_templates): + plugins = [] + for node in node_templates: + if self._isPlugin(node): + plugin = {} + plugin['plugin_id'] = node['name'] + plugin['description'] = node['description'] + plugin['properties'] = node['properties'] + if 'interfaces' in node: + plugin['interfaces'] = node['interfaces'] + + plugins.append(plugin) + return plugins + + def _isPlugin(self, node): + return node['nodeType'].lower().find('.plugin.') >= 0 or node['nodeType'].lower().endswith('.plugin') + + def _get_all_element_group(self, groups): + rets = [] + for group in groups: + if self._isVnfdElementGroup(group): + ret = {} + ret['group_id'] = group.name + ret['description'] = group.description + if 'properties' in group.tpl: + ret['properties'] = group.tpl['properties'] + ret['members'] = group.members + rets.append(ret) + return rets + + def _isVnfdElementGroup(self, group): + return group.type.upper().find('.VNFDELEMENTGROUP.') >= 0 or group.type.upper().endswith('.VNFDELEMENTGROUP') diff --git a/lcm/swagger/vfc.nslcm.swagger.json b/lcm/swagger/vfc.nslcm.swagger.json index 528ec672..0a8fc095 100644 --- a/lcm/swagger/vfc.nslcm.swagger.json +++ b/lcm/swagger/vfc.nslcm.swagger.json @@ -56,13 +56,21 @@ ],
"summary": "ns get",
"description": "ns get",
- "operationId": "ns_get",
- "parameters": [],
+ "operationId": "ns_instantces_get",
+ "parameters": [
+ {
+ "required": true,
+ "type": "string",
+ "description": "job response message id",
+ "name": "csarId",
+ "in": "query"
+ }
+ ],
"responses": {
"200": {
"description": "successful operation",
"schema": {
- "$ref": "#/definitions/NsInfo"
+ "$ref": "#/definitions/NsInstancesInfo"
}
}
}
@@ -225,6 +233,23 @@ }
},
"/ns/{ns_instance_id}": {
+ "get": {
+ "tags": [
+ "ns"
+ ],
+ "summary": "ns get",
+ "description": "ns get",
+ "operationId": "ns_instance_get",
+ "parameters": [],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "$ref": "#/definitions/NsInstanceInfo"
+ }
+ }
+ }
+ },
"delete": {
"tags": [
"ns"
@@ -411,8 +436,13 @@ }
}
},
-
- "NsInfo": {
+ "NsInstancesInfo":{
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/NsInstanceInfo"
+ }
+ },
+ "NsInstanceInfo": {
"type": "object",
"properties": {
"nsInstanceId": {
|