diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-19 15:36:33 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-19 15:36:33 +0800 |
commit | 4d52387b3556f146bea3533106955c8f7a27571f (patch) | |
tree | 008a71fb6a718ba137c0794a3e5b57b36fd903e7 | |
parent | 5a19d31c7e350aadfc8332792b2555bc46a9f019 (diff) |
refactor codes for update vnf
Change-Id: Ibc224865cdf9d9e133959e7bdcc52af16ef4ea8c
Issue-ID: VFC-1307
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/lcm/nf/views/common.py | 5 | ||||
-rw-r--r-- | lcm/lcm/nf/views/curd_vnf_views.py | 34 |
2 files changed, 14 insertions, 25 deletions
diff --git a/lcm/lcm/nf/views/common.py b/lcm/lcm/nf/views/common.py index 1f6b6b01..9e039a97 100644 --- a/lcm/lcm/nf/views/common.py +++ b/lcm/lcm/nf/views/common.py @@ -107,7 +107,7 @@ def deal_vnf_action(logger, opt_type, opt_status, instid, req, req_serializer, a if opt_type == OPERATION_TYPE.INSTANTIATE: if vnf_insts[0].status == 'INSTANTIATED': raise NFLCMExceptionConflict("VNF(%s) is already INSTANTIATED." % instid) - else: + elif opt_type != OPERATION_TYPE.MODIFY_INFO: if vnf_insts[0].status != 'INSTANTIATED': raise NFLCMExceptionConflict("VNF(%s) is not INSTANTIATED." % instid) @@ -117,5 +117,4 @@ def deal_vnf_action(logger, opt_type, opt_status, instid, req, req_serializer, a vnf_insts.update(status=opt_status) act_task(req.data, instid, job_id).start() - resp = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED) - return resp + return Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED) diff --git a/lcm/lcm/nf/views/curd_vnf_views.py b/lcm/lcm/nf/views/curd_vnf_views.py index 64fe0029..6c646f1f 100644 --- a/lcm/lcm/nf/views/curd_vnf_views.py +++ b/lcm/lcm/nf/views/curd_vnf_views.py @@ -15,7 +15,6 @@ import logging from drf_yasg.utils import swagger_auto_schema -from lcm.nf.biz.delete_vnf import DeleteVnf from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView @@ -23,16 +22,16 @@ from rest_framework.views import APIView from lcm.nf.biz.create_vnf import CreateVnf from lcm.nf.biz.query_vnf import QueryVnf from lcm.nf.biz.update_vnf import UpdateVnf +from lcm.nf.biz.delete_vnf import DeleteVnf from lcm.nf.serializers.create_vnf_req import CreateVnfReqSerializer from lcm.nf.serializers.vnf_instance import VnfInstanceSerializer from lcm.nf.serializers.vnf_instances import VnfInstancesSerializer from lcm.nf.serializers.vnf_info_modifications import VnfInfoModificationsSerializer -from lcm.pub.utils.jobutil import JobUtil from lcm.pub.exceptions import NFLCMException -from lcm.pub.exceptions import NFLCMExceptionNotFound -from lcm.pub.database.models import NfInstModel from lcm.nf.const import VNF_STATUS +from lcm.nf.const import OPERATION_TYPE from .common import view_safe_call_with_log +from .common import deal_vnf_action logger = logging.getLogger(__name__) @@ -123,21 +122,12 @@ class DeleteVnfAndQueryVnf(APIView): ) @view_safe_call_with_log(logger=logger) def patch(self, request, instanceid): - logger.debug("UpdateSingleVnf--patch::> %s, %s", instanceid, request.data) - - upd_vnf_serializer = VnfInfoModificationsSerializer(data=request.data) - if not upd_vnf_serializer.is_valid(): - raise NFLCMException(upd_vnf_serializer.errors) - - job_id = JobUtil.create_job('NF', 'UPDATE', instanceid) - JobUtil.add_job_status(job_id, 0, "UPDATE_VNF_READY") - - vnf_insts = NfInstModel.objects.filter(nfinstid=instanceid) - if not vnf_insts.exists(): - raise NFLCMExceptionNotFound("VNF(%s) does not exist." % instanceid) - vnf_insts.update(status=VNF_STATUS.UPDATING) - - JobUtil.add_job_status(job_id, 15, 'Nf updating pre-check finish') - UpdateVnf(request.data, instanceid, job_id).start() - - return Response(data=None, status=status.HTTP_202_ACCEPTED) + return deal_vnf_action( + logger=logger, + opt_type=OPERATION_TYPE.MODIFY_INFO, + opt_status=VNF_STATUS.UPDATING, + instid=instanceid, + req=request, + req_serializer=VnfInfoModificationsSerializer, + act_task=UpdateVnf + ) |