From 92e6a03c204c17100a786da0746ff513d475001b Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Thu, 9 Feb 2017 16:28:20 +0800 Subject: Decomposition instantiation process Change-Id: I4579af8d50ad18901564cd8546a060b16ca1486c Issue-Id: GVNFM-7 Signed-off-by: ying.yunlong --- lcm/lcm/nf/vnfs/create_vnfs.py | 115 --------------------------------- lcm/lcm/nf/vnfs/views.py | 3 +- lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py | 115 +++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 116 deletions(-) delete mode 100644 lcm/lcm/nf/vnfs/create_vnfs.py create mode 100644 lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py diff --git a/lcm/lcm/nf/vnfs/create_vnfs.py b/lcm/lcm/nf/vnfs/create_vnfs.py deleted file mode 100644 index 0dc5216c..00000000 --- a/lcm/lcm/nf/vnfs/create_vnfs.py +++ /dev/null @@ -1,115 +0,0 @@ -# Copyright 2017 ZTE Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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 logging -import traceback -from threading import Thread - -from lcm.pub.exceptions import NFLCMException - -logger = logging.getLogger(__name__) - - -class CreateVnfs(Thread): - def __init__(self, data, nf_inst_id, job_id): - super(CreateVnfs, self).__init__() - self.data = data - self.nf_inst_id = nf_inst_id - self.job_id = job_id - - def run(self): - try: - args = {} - self.inst_pre(args) - self.apply_grant(args) - self.apply_res(args) - self.check_res_status(args) - self.wait_inst_finish(args) - self.lcm_notify(args) - except NFLCMException as e: - self.inst_exception(e.message) - pass - except Exception: - logger.error(traceback.format_exc()) - self.inst_exception('unexpected exception') - - def inst_pre(self, args): - try: - logger.info('inst_pre, args=%s' % args) - # InstPreTask(args).do_biz() - return {'result': '100', 'sessionid': '', 'msg': 'Nf instancing preprocess finish', 'context': {}} - except Exception as e: - logger.error('Nf instancing preprocess exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing preprocess exception', 'context': {}} - - def apply_grant(self, args): - try: - logger.info('apply_grant, args=%s' % args) - # ApplyGrantTask(args).do_biz() - return {'result': '100', 'msg': 'Nf instancing apply grant finish', 'context': {}} - except Exception as e: - logger.error('Nf instancing apply grant exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing apply grant exception', 'context': {}} - - def apply_res(self, args): - try: - logger.info('apply_res, args=%s' % args) - # ApplyResTask(args).do_biz() - return {'result': '100', 'msg': 'Nf instancing apply resource finish', 'context': {}} - except Exception as e: - logger.error('Nf instancing apply resource exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing apply resource exception', 'context': {}} - - def check_res_status(self, args): - try: - logger.info('check_res_status, args=%s' % args) - # CheckResStatusTask(args).do_biz() - return {'result': '100', 'msg': 'Nf instancing check resource status finish', 'context': {}} - except Exception as e: - logger.error('Nf instancing check resource status exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing check resource status exception', 'context': {}} - - def wait_inst_finish(self, args): - try: - logger.info('wait_inst_finish, args=%s' % args) - # WaitInstFinishTask(args).do_biz() - return {'result': '100', 'msg': 'Nf instancing wait finish', 'context': {}} - except Exception as e: - logger.error('Nf instancing wait exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing wait exception', 'context': {}} - - def lcm_notify(self, args): - try: - logger.info('lcm_notify, args=%s' % args) - # LcmNotifyTask(args).do_biz() - return {'result': '100', 'msg': 'Nf instancing lcm notify finish', 'context': {}} - except Exception as e: - logger.error('Nf instancing lcm notify exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing lcm notify exception', 'context': {}} - - def inst_exception(self, args): - try: - logger.info('inst_exception, args=%s' % args) - # InstExceptionTask(args).do_biz() - return {'result': '100', 'msg': 'Nf instancing exception process finish', 'context': {}} - except Exception as e: - logger.error('Nf instancing exception process exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing exception process exception', 'context': {}} \ No newline at end of file diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py index c47e5004..d1818a5a 100644 --- a/lcm/lcm/nf/vnfs/views.py +++ b/lcm/lcm/nf/vnfs/views.py @@ -19,6 +19,7 @@ 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.utils.jobutil import JobUtil from lcm.pub.utils.values import ignore_case_get @@ -52,7 +53,7 @@ class InstantiateVnf(APIView): job_id = JobUtil.create_job('NF', 'CREATE', nf_inst_id) JobUtil.add_job_status(job_id, 0, "INST_VNF_READY") - # CreateVnfs(data, nf_inst_id, job_id).start() + InstVnf(data, nf_inst_id, job_id).start() rsp = {"jobId": job_id} return Response(data=rsp, status=status.HTTP_202_ACCEPTED) diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py new file mode 100644 index 00000000..258b863b --- /dev/null +++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py @@ -0,0 +1,115 @@ +# Copyright 2017 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 logging +import traceback +from threading import Thread + +from lcm.pub.exceptions import NFLCMException + +logger = logging.getLogger(__name__) + + +class InstVnf(Thread): + def __init__(self, data, nf_inst_id, job_id): + super(InstVnf, self).__init__() + self.data = data + self.nf_inst_id = nf_inst_id + self.job_id = job_id + + def run(self): + try: + args = {} + self.inst_pre(args) + self.apply_grant(args) + self.apply_res(args) + self.check_res_status(args) + self.wait_inst_finish(args) + self.lcm_notify(args) + except NFLCMException as e: + self.inst_exception(e.message) + pass + except Exception: + logger.error(traceback.format_exc()) + self.inst_exception('unexpected exception') + + def inst_pre(self, args): + try: + logger.info('inst_pre, args=%s' % args) + # InstPreTask(args).do_biz() + return {'result': '100', 'sessionid': '', 'msg': 'Nf instancing preprocess finish', 'context': {}} + except Exception as e: + logger.error('Nf instancing preprocess exception=%s' % e.message) + logger.error(traceback.format_exc()) + return {'result': '255', 'msg': 'Nf instancing preprocess exception', 'context': {}} + + def apply_grant(self, args): + try: + logger.info('apply_grant, args=%s' % args) + # ApplyGrantTask(args).do_biz() + return {'result': '100', 'msg': 'Nf instancing apply grant finish', 'context': {}} + except Exception as e: + logger.error('Nf instancing apply grant exception=%s' % e.message) + logger.error(traceback.format_exc()) + return {'result': '255', 'msg': 'Nf instancing apply grant exception', 'context': {}} + + def apply_res(self, args): + try: + logger.info('apply_res, args=%s' % args) + # ApplyResTask(args).do_biz() + return {'result': '100', 'msg': 'Nf instancing apply resource finish', 'context': {}} + except Exception as e: + logger.error('Nf instancing apply resource exception=%s' % e.message) + logger.error(traceback.format_exc()) + return {'result': '255', 'msg': 'Nf instancing apply resource exception', 'context': {}} + + def check_res_status(self, args): + try: + logger.info('check_res_status, args=%s' % args) + # CheckResStatusTask(args).do_biz() + return {'result': '100', 'msg': 'Nf instancing check resource status finish', 'context': {}} + except Exception as e: + logger.error('Nf instancing check resource status exception=%s' % e.message) + logger.error(traceback.format_exc()) + return {'result': '255', 'msg': 'Nf instancing check resource status exception', 'context': {}} + + def wait_inst_finish(self, args): + try: + logger.info('wait_inst_finish, args=%s' % args) + # WaitInstFinishTask(args).do_biz() + return {'result': '100', 'msg': 'Nf instancing wait finish', 'context': {}} + except Exception as e: + logger.error('Nf instancing wait exception=%s' % e.message) + logger.error(traceback.format_exc()) + return {'result': '255', 'msg': 'Nf instancing wait exception', 'context': {}} + + def lcm_notify(self, args): + try: + logger.info('lcm_notify, args=%s' % args) + # LcmNotifyTask(args).do_biz() + return {'result': '100', 'msg': 'Nf instancing lcm notify finish', 'context': {}} + except Exception as e: + logger.error('Nf instancing lcm notify exception=%s' % e.message) + logger.error(traceback.format_exc()) + return {'result': '255', 'msg': 'Nf instancing lcm notify exception', 'context': {}} + + def inst_exception(self, args): + try: + logger.info('inst_exception, args=%s' % args) + # InstExceptionTask(args).do_biz() + return {'result': '100', 'msg': 'Nf instancing exception process finish', 'context': {}} + except Exception as e: + logger.error('Nf instancing exception process exception=%s' % e.message) + logger.error(traceback.format_exc()) + return {'result': '255', 'msg': 'Nf instancing exception process exception', 'context': {}} \ No newline at end of file -- cgit 1.2.3-korg