X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fnf%2Fvnfs%2Fviews.py;h=f03e4bcf692771544bf7ebe9618cbafa01cfd44d;hb=292f01ff313671718e9135689e5517be1c397d39;hp=c47e5004ce75d90e6066fbe9c472af6ce1f73887;hpb=852d84e026b178497f5f54c13aeaa0f518770307;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py index c47e5004..f03e4bcf 100644 --- a/lcm/lcm/nf/vnfs/views.py +++ b/lcm/lcm/nf/vnfs/views.py @@ -11,16 +11,19 @@ # 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 json import logging +import os +import traceback from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf +from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf +from lcm.pub.exceptions import NFLCMException from lcm.pub.utils.jobutil import JobUtil -from lcm.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) @@ -28,31 +31,24 @@ logger = logging.getLogger(__name__) class CreateVnfIdentifier(APIView): def post(self, request): logger.debug("CreateVnfIdentifier--post::> %s" % request.data) - data = {} - data["vnfdId"] = ignore_case_get(request.data, "vnfdId") - data["vnfInstanceName"] = ignore_case_get(request.data, "vnfInstanceName") - data["vnfInstanceDescription"] = ignore_case_get(request.data, "vnfInstanceDescription") try: - self.nf_inst_id = CreateVnf(data).do_biz() - except Exception as e: + nf_inst_id = CreateVnf(request.data).do_biz() + except NFLCMException as e: + logger.error(e.message) return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - rsp = {"vnfInstanceId": self.nf_inst_id} + except Exception: + logger.error(traceback.format_exc()) + return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + rsp = {"vnfInstanceId": nf_inst_id} return Response(data=rsp, status=status.HTTP_201_CREATED) class InstantiateVnf(APIView): def post(self, request, instanceId): logger.debug("InstantiateVnf--post::> %s" % request.data) - data = {'flavourId': ignore_case_get(request.data, 'flavourId'), - 'instantiationLevelId': ignore_case_get(request.data, 'instantiationLevelId'), - 'extVirtualLinks': ignore_case_get(request.data, 'extVirtualLinks'), - 'localizationLanguage': ignore_case_get(request.data, 'localizationLanguage'), - 'additionalParams': ignore_case_get(request.data, 'additionalParams')} - nf_inst_id = instanceId - job_id = JobUtil.create_job('NF', 'CREATE', nf_inst_id) + job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceId) JobUtil.add_job_status(job_id, 0, "INST_VNF_READY") - - # CreateVnfs(data, nf_inst_id, job_id).start() + InstVnf(request.data, instanceId, job_id).start() rsp = {"jobId": job_id} return Response(data=rsp, status=status.HTTP_202_ACCEPTED) @@ -60,7 +56,7 @@ class InstantiateVnf(APIView): class DeleteVnfIdentifier(APIView): def delete(self, request): logger.debug("DeleteVnfIdentifier--delete::> %s" % request.data) - return Response(data='', status=status.HTTP_202_ACCEPTED) + return Response(data='', status=status.HTTP_204_NO_CONTENT) class TerminateVnf(APIView): @@ -84,4 +80,13 @@ class QuerySingleVnf(APIView): class GetOperationStatus(APIView): def get(self, request): logger.debug("GetOperationStatus--get::> %s" % request.data) - return Response(data='', status=status.HTTP_202_ACCEPTED) \ No newline at end of file + return Response(data='', status=status.HTTP_202_ACCEPTED) + + +class SwaggerJsonView(APIView): + def get(self, request): + json_file = os.path.join(os.path.dirname(__file__), 'swagger.json') + f = open(json_file) + json_data = json.JSONDecoder().decode(f.read()) + f.close() + return Response(json_data)