diff options
author | 2019-04-19 13:49:34 +0800 | |
---|---|---|
committer | 2019-04-19 13:49:34 +0800 | |
commit | c52d0a5253b56589457c9180a6f68c1bc1edb4ef (patch) | |
tree | 54bf48e242fb44641963088a8d1e0faa7406bf11 /lcm/lcm/nf | |
parent | 0184dcbf1f00b61a6ab990081aebfb6f51dda95a (diff) |
refactor codes for instantiate vnf
Change-Id: I1ccefebd93fdef4299b678f68b4ee7bae6adc1f8
Issue-ID: VFC-1307
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm/lcm/nf')
-rw-r--r-- | lcm/lcm/nf/views/instantiate_vnf_view.py | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/lcm/lcm/nf/views/instantiate_vnf_view.py b/lcm/lcm/nf/views/instantiate_vnf_view.py index 23a979ae..cc17d48b 100644 --- a/lcm/lcm/nf/views/instantiate_vnf_view.py +++ b/lcm/lcm/nf/views/instantiate_vnf_view.py @@ -15,19 +15,16 @@ import logging
from drf_yasg.utils import swagger_auto_schema
-from lcm.nf.biz.instantiate_vnf import InstantiateVnf
from rest_framework import status
-from rest_framework.response import Response
from rest_framework.views import APIView
from lcm.nf.serializers.instantiate_vnf_request import InstantiateVnfRequestSerializer
from lcm.nf.serializers.job_identifier import JobIdentifierSerializer
-from lcm.pub.exceptions import NFLCMException
-from lcm.pub.exceptions import NFLCMExceptionNotFound
-from lcm.pub.exceptions import NFLCMExceptionConflict
-from lcm.pub.utils.jobutil import JobUtil
-from lcm.pub.database.models import NfInstModel
+from lcm.nf.biz.instantiate_vnf import InstantiateVnf
+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__)
@@ -42,25 +39,12 @@ class InstantiateVnfView(APIView): )
@view_safe_call_with_log(logger=logger)
def post(self, request, instanceid):
- logger.debug("InstantiateVnf--post::> %s" % request.data)
-
- instantiate_vnf_request_serializer = InstantiateVnfRequestSerializer(data=request.data)
- if not instantiate_vnf_request_serializer.is_valid():
- raise NFLCMException(instantiate_vnf_request_serializer.errors)
-
- vnf_insts = NfInstModel.objects.filter(nfinstid=instanceid)
- if not vnf_insts.exists():
- raise NFLCMExceptionNotFound("VNF instanceid(%s) does not exist." % instanceid)
- if vnf_insts[0].status == 'INSTANTIATED':
- raise NFLCMExceptionConflict('VNF(%s) is already INSTANTIATED.' % instanceid)
-
- job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid)
- JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
- InstantiateVnf(instantiate_vnf_request_serializer.data, instanceid, job_id).start()
-
- job_identifier_serializer = JobIdentifierSerializer(data={"jobId": job_id})
- resp_isvalid = job_identifier_serializer.is_valid()
- if not resp_isvalid:
- raise NFLCMException(job_identifier_serializer.errors)
-
- return Response(data=job_identifier_serializer.data, status=status.HTTP_202_ACCEPTED)
+ return deal_vnf_action(
+ logger=logger,
+ opt_type=OPERATION_TYPE.INSTANTIATE,
+ opt_status=VNF_STATUS.INSTANTIATING,
+ instid=instanceid,
+ req=request,
+ req_serializer=InstantiateVnfRequestSerializer,
+ act_task=InstantiateVnf
+ )
|