diff options
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/nf/vnfs/tests/test_vnf_query.py | 69 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/urls.py | 10 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/views.py | 19 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_query/query_vnf.py | 10 |
4 files changed, 96 insertions, 12 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_query.py b/lcm/lcm/nf/vnfs/tests/test_vnf_query.py index 9e7490a7..bc88b95c 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_query.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_query.py @@ -22,7 +22,7 @@ class ResourceTest(TestCase): self.client = Client() self.nf_inst_id = "01" NfInstModel.objects.all().delete() - self.test_data = { + self.test_data_single_vnf = { "vnfInstanceId": "1", "vnfInstanceName": "VNF1", "vnfProvider": None, @@ -49,6 +49,62 @@ class ResourceTest(TestCase): "vnfdVersion": None, "onboardedVnfPkgInfoId": None } + self.test_data_multi_vnf = [ + { + "vnfInstanceId": "1", + "vnfInstanceName": "VNF1", + "vnfProvider": None, + "instantiatedVnfInfo": { + "vnfState": None, + "extCpInfo": [], + "virtualStorageResourceInfo": [ + { + "virtualStorageInstanceId": "s01", + "storageResource": { + "resourceId": "resource01", + "vimId": "vim01" + } + } + ], + "extVirtualLink": [], + "vnfcResourceInfo": [], + "monitoringParameters": {}, + "vimInfo": [], + "flavourId": None, + "virtualLinkResourceInfo": [], + "scaleStatus": [] + }, + "vnfdVersion": None, + "onboardedVnfPkgInfoId": None + }, + { + "vnfInstanceId": "2", + "vnfInstanceName": "VNF2", + "vnfProvider": None, + "instantiatedVnfInfo": { + "vnfState": None, + "extCpInfo": [], + "virtualStorageResourceInfo": [ + { + "virtualStorageInstanceId": "s02", + "storageResource": { + "resourceId": "resource02", + "vimId": "vim02" + } + } + ], + "extVirtualLink": [], + "vnfcResourceInfo": [], + "monitoringParameters": {}, + "vimInfo": [], + "flavourId": None, + "virtualLinkResourceInfo": [], + "scaleStatus": [] + }, + "vnfdVersion": None, + "onboardedVnfPkgInfoId": None + } + ] def tearDown(self): pass @@ -60,4 +116,13 @@ class ResourceTest(TestCase): instid=vnf_inst_id).save() response = self.client.get("/openoapi/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(self.test_data, response.data)
\ No newline at end of file + self.assertEqual(self.test_data_single_vnf, response.data) + + def test_get_vnfs(self): + for i in range(1,3): + NfInstModel(nfinstid='%s' % i, nf_name='VNF%s' % i).save() + StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, resouceid='resource0%s' % i, + insttype=1, instid='%s' % i).save() + response = self.client.get("/openoapi/vnflcm/v1/vnf_instances") + self.failUnlessEqual(status.HTTP_200_OK, response.status_code) + self.assertEqual(self.test_data_multi_vnf, response.data)
\ No newline at end of file diff --git a/lcm/lcm/nf/vnfs/urls.py b/lcm/lcm/nf/vnfs/urls.py index 00788783..4857f429 100644 --- a/lcm/lcm/nf/vnfs/urls.py +++ b/lcm/lcm/nf/vnfs/urls.py @@ -15,18 +15,18 @@ from django.conf.urls import patterns, url from rest_framework.urlpatterns import format_suffix_patterns -from lcm.nf.vnfs.views import CreateVnfIdentifier, InstantiateVnf, QueryMultipleVnf,\ - TerminateVnf, SwaggerJsonView, DetailVnf +from lcm.nf.vnfs.views import InstantiateVnf, QueryMultipleVnf,\ + TerminateVnf, SwaggerJsonView, DeleteVnfAndQueryVnf, CreateVnfAndQueryVnfs urlpatterns = patterns('', - url(r'^openoapi/vnflcm/v1/vnf_instances$', CreateVnfIdentifier.as_view()), + url(r'^openoapi/vnflcm/v1/vnf_instances$', CreateVnfAndQueryVnfs.as_view()), url(r'^openoapi/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/instantiate$', InstantiateVnf.as_view()), url(r'^openoapi/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)$', - DetailVnf.as_view()), + DeleteVnfAndQueryVnf.as_view()), url(r'^openoapi/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/terminate$', TerminateVnf.as_view()), - url(r'^openoapi/vnflcm/v1/vnf_instances$', QueryMultipleVnf.as_view()), + # url(r'^openoapi/vnflcm/v1/vnf_instances$', QueryMultipleVnf.as_view()), # url(r'^openoapi/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)$', # QuerySingleVnf.as_view()), # url(r'^openoapi/vnflcm/v1/vnf_lc_ops/(?P<vnfLcOpId>[0-9a-zA-Z_-]+)&' diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py index b88a3e16..a97c6169 100644 --- a/lcm/lcm/nf/vnfs/views.py +++ b/lcm/lcm/nf/vnfs/views.py @@ -32,7 +32,21 @@ from lcm.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) -class CreateVnfIdentifier(APIView): +class CreateVnfAndQueryVnfs(APIView): + def get(self, request): + logger.debug("QuerySingleVnf--get::> %s" % request.data) + try: + resp_data = QueryVnf(request.data).query_multi_vnf() + except NFLCMException as e: + logger.error(e.message) + return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + except: + logger.error(traceback.format_exc()) + tt = traceback.format_exc() + return Response(data={'error': 'Failed to get Vnfs'}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(data=resp_data, status=status.HTTP_200_OK) + def post(self, request): logger.debug("CreateVnfIdentifier--post::> %s" % request.data) try: @@ -64,7 +78,7 @@ class InstantiateVnf(APIView): return Response(data=rsp, status=status.HTTP_202_ACCEPTED) -class DetailVnf(APIView): +class DeleteVnfAndQueryVnf(APIView): def get(self, request, instanceid): logger.debug("QuerySingleVnf--get::> %s" % request.data) try: @@ -74,7 +88,6 @@ class DetailVnf(APIView): return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) except: logger.error(traceback.format_exc()) - tt = traceback.format_exc() return Response(data={'error': 'Failed to get Vnf(%s)' % instanceid}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(data=resp_data, status=status.HTTP_200_OK) diff --git a/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py b/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py index 6526e731..7f4dc8da 100644 --- a/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py @@ -21,7 +21,7 @@ logger = logging.getLogger(__name__) class QueryVnf: - def __init__(self, data, instanceid): + def __init__(self, data, instanceid=''): self.vnf_inst_id = instanceid self.data = data pass @@ -34,7 +34,13 @@ class QueryVnf: return resp_data def query_multi_vnf(self): - pass + vnf_insts = NfInstModel.objects.all() + if not vnf_insts: + raise NFLCMException('VnfInsts does not exist') + resp_data = [] + for vnf_inst in vnf_insts: + resp_data.append(self.fill_resp_data(vnf_inst)) + return resp_data def fill_resp_data(self, vnf): logger.info('Get the list of vloumes') |