summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-19 11:44:28 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-19 11:44:28 +0800
commit1306f9c091fadb8cdd5a6b34aef046524872cfda (patch)
treef0bf25c995c752eb33fae80afcb7673892f86da7 /lcm
parent74c937ccfbdaa77c8377d209e4b22156a3137a15 (diff)
refactor codes for vnflcm
Change-Id: Ic9fbaa0cc72ebb59eefe53aea370f86e81442b2d Issue-ID: VFC-1307 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/views/common.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/lcm/lcm/nf/views/common.py b/lcm/lcm/nf/views/common.py
index 1be6a5de..1f6b6b01 100644
--- a/lcm/lcm/nf/views/common.py
+++ b/lcm/lcm/nf/views/common.py
@@ -24,6 +24,9 @@ from lcm.pub.exceptions import NFLCMExceptionBadRequest
from lcm.pub.exceptions import NFLCMExceptionNotFound
from lcm.pub.exceptions import NFLCMExceptionConflict
from lcm.pub.exceptions import NFLCMExceptionSeeOther
+from lcm.pub.database.models import NfInstModel
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.nf.const import OPERATION_TYPE
logger = logging.getLogger(__name__)
@@ -88,3 +91,31 @@ def view_safe_call_with_log(logger):
)
return wrapper
return view_safe_call
+
+
+def deal_vnf_action(logger, opt_type, opt_status, instid, req, req_serializer, act_task):
+ logger.debug("%s--post::> %s, %s", opt_type, instid, req.data)
+
+ act_vnf_req_serializer = req_serializer(data=req.data)
+ if not act_vnf_req_serializer.is_valid():
+ raise NFLCMException(act_vnf_req_serializer.errors)
+
+ vnf_insts = NfInstModel.objects.filter(nfinstid=instid)
+ if not vnf_insts.exists():
+ raise NFLCMExceptionNotFound("VNF(%s) does not exist." % instid)
+
+ if opt_type == OPERATION_TYPE.INSTANTIATE:
+ if vnf_insts[0].status == 'INSTANTIATED':
+ raise NFLCMExceptionConflict("VNF(%s) is already INSTANTIATED." % instid)
+ else:
+ if vnf_insts[0].status != 'INSTANTIATED':
+ raise NFLCMExceptionConflict("VNF(%s) is not INSTANTIATED." % instid)
+
+ job_id = JobUtil.create_job('NF', opt_type, instid)
+ JobUtil.add_job_status(job_id, 0, "VNF_%s_READY" % opt_type)
+
+ 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