diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-24 17:06:03 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-24 17:11:18 +0800 |
commit | d7625e7a223854556603a3590a881e033c655210 (patch) | |
tree | 66cfb4e25fac7cab9828c4dd066a518c2d28d98a /lcm | |
parent | 3f63b351c906c800c0aba78f6b72914fa49239fe (diff) |
Add lcm op occ to operate heal
Change-Id: I313f444a272b4606db99cb77f7a12080958b3700
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/nf/biz/change_ext_conn.py | 4 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/change_vnf_flavour.py | 3 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/heal_vnf.py | 12 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/operate_vnf.py | 60 |
4 files changed, 60 insertions, 19 deletions
diff --git a/lcm/lcm/nf/biz/change_ext_conn.py b/lcm/lcm/nf/biz/change_ext_conn.py index ef14b8cc..cbc65716 100644 --- a/lcm/lcm/nf/biz/change_ext_conn.py +++ b/lcm/lcm/nf/biz/change_ext_conn.py @@ -65,7 +65,7 @@ class ChangeExtConn(Thread): status='INSTANTIATED', lastuptime=now_time() ) - self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.COMPLETED) + self.send_notification() JobUtil.add_job_status(self.job_id, 100, "Change ext conn success.") @@ -176,7 +176,7 @@ class ChangeExtConn(Thread): def send_notification(self): data = prepare_notification(nfinstid=self.nf_inst_id, jobid=self.job_id, - operation=self.op_type, + operation=OPERATION_TYPE.CHANGE_EXT_CONN, operation_state=OPERATION_STATE_TYPE.COMPLETED) self.set_ext_connectivity(data['changedExtConnectivity']) diff --git a/lcm/lcm/nf/biz/change_vnf_flavour.py b/lcm/lcm/nf/biz/change_vnf_flavour.py index 7d87fe84..9b9db6e7 100644 --- a/lcm/lcm/nf/biz/change_vnf_flavour.py +++ b/lcm/lcm/nf/biz/change_vnf_flavour.py @@ -64,7 +64,6 @@ class ChangeVnfFlavour(Thread): lastuptime=now_time() ) self.send_notification() - self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.COMPLETED) JobUtil.add_job_status(self.job_id, 100, "Change vnf flavour success.") @@ -95,7 +94,7 @@ class ChangeVnfFlavour(Thread): data = prepare_notification_data(nfinstid=self.nf_inst_id, jobid=self.job_id, changetype=CHANGE_TYPE.MODIFIED, - operation=self.op_type) + operation=OPERATION_TYPE.CHANGE_FLAVOUR) logger.debug('Notify request data = %s' % data) NotificationsUtil().send_notification(data) diff --git a/lcm/lcm/nf/biz/heal_vnf.py b/lcm/lcm/nf/biz/heal_vnf.py index 535ad633..5b061d33 100644 --- a/lcm/lcm/nf/biz/heal_vnf.py +++ b/lcm/lcm/nf/biz/heal_vnf.py @@ -23,6 +23,7 @@ from lcm.pub.database.models import VmInstModel from lcm.pub.database.models import VNFCInstModel from lcm.pub.exceptions import NFLCMException from lcm.pub.utils.jobutil import JobUtil +from lcm.pub.utils.notificationsutil import NotificationsUtil from lcm.pub.utils.timeutil import now_time from lcm.pub.utils.values import ignore_case_get from lcm.pub.vimapi import adaptor @@ -70,7 +71,10 @@ class HealVnf(Thread): status='INSTANTIATED', lastuptime=now_time() ) - self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.COMPLETED) + self.lcm_notify( + LCM_NOTIFICATION_STATUS.RESULT, + OPERATION_STATE_TYPE.COMPLETED + ) except NFLCMException as e: logger.error(e.message) self.vnf_heal_failed_handle(e.message) @@ -135,6 +139,12 @@ class HealVnf(Thread): self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, error_msg) JobUtil.add_job_status(self.job_id, 255, error_msg) + def lcm_notify(self, status, opState, err=None): + notification_content = self.prepareNotificationData(status, opState, err) + logger.info('Notify data = %s' % notification_content) + NotificationsUtil().send_notification(notification_content) + logger.info('Notify end') + def prepareNotificationData(self, status, opState, err=None): affected_vnfcs = [] if status == LCM_NOTIFICATION_STATUS.RESULT and opState == OPERATION_STATE_TYPE.COMPLETED: diff --git a/lcm/lcm/nf/biz/operate_vnf.py b/lcm/lcm/nf/biz/operate_vnf.py index d4381de5..775def30 100644 --- a/lcm/lcm/nf/biz/operate_vnf.py +++ b/lcm/lcm/nf/biz/operate_vnf.py @@ -15,9 +15,12 @@ # import json import logging import traceback +import uuid from threading import Thread -from lcm.pub.database.models import NfInstModel, VmInstModel, VNFCInstModel +from lcm.pub.database.models import NfInstModel +from lcm.pub.database.models import VmInstModel +from lcm.pub.database.models import VNFCInstModel from lcm.pub.exceptions import NFLCMException from lcm.pub.utils.jobutil import JobUtil from lcm.pub.utils.timeutil import now_time @@ -25,8 +28,15 @@ from lcm.pub.utils.notificationsutil import NotificationsUtil from lcm.pub.utils.values import ignore_case_get from lcm.pub.vimapi import adaptor from lcm.nf.biz.grant_vnf import grant_resource -from lcm.nf.const import VNF_STATUS, RESOURCE_MAP, GRANT_TYPE, OPERATION_STATE_TYPE, LCM_NOTIFICATION_STATUS, CHANGE_TYPE, OPERATION_TYPE -import uuid +from lcm.nf.const import VNF_STATUS +from lcm.nf.const import RESOURCE_MAP +from lcm.nf.const import GRANT_TYPE +from lcm.nf.const import OPERATION_STATE_TYPE +from lcm.nf.const import LCM_NOTIFICATION_STATUS +from lcm.nf.const import CHANGE_TYPE +from lcm.nf.const import OPERATION_TYPE +from lcm.nf.const import OPERATION_TASK +from .operate_vnf_lcm_op_occ import VnfLcmOpOcc logger = logging.getLogger(__name__) @@ -42,29 +52,43 @@ class OperateVnf(Thread): self.stopType = ignore_case_get(self.data, "stopType") self.gracefulStopTimeout = ignore_case_get(self.data, "gracefulStopTimeout") self.inst_resource = {'vm': []} + self.lcm_op_occ = VnfLcmOpOcc( + vnf_inst_id=nf_inst_id, + lcm_op_id=job_id, + operation=OPERATION_TYPE.OPERATE, + task=OPERATION_TASK.OPERATE + ) def run(self): try: - self.lcm_notify(LCM_NOTIFICATION_STATUS.START, OPERATION_STATE_TYPE.STARTING) + self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.STARTING) self.apply_grant() self.query_inst_resource() - self.lcm_notify(LCM_NOTIFICATION_STATUS.RESULT, OPERATION_STATE_TYPE.PROCESSING) + self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.PROCESSING) self.operate_resource() JobUtil.add_job_status(self.job_id, 100, "Operate Vnf success.") - NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='INSTANTIATED', lastuptime=now_time()) - self.lcm_notify(LCM_NOTIFICATION_STATUS.RESULT, OPERATION_STATE_TYPE.COMPLETED) + NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update( + status='INSTANTIATED', + lastuptime=now_time() + ) + self.lcm_notify( + LCM_NOTIFICATION_STATUS.RESULT, + OPERATION_STATE_TYPE.COMPLETED + ) except NFLCMException as e: - self.lcm_notify(LCM_NOTIFICATION_STATUS.RESULT, OPERATION_STATE_TYPE.FAILED, str(e)) self.vnf_operate_failed_handle(e.message) except Exception as e: logger.error(e.message) - self.lcm_notify(LCM_NOTIFICATION_STATUS.RESULT, OPERATION_STATE_TYPE.FAILED, str(e)) - self.vnf_operate_failed_handle(traceback.format_exc()) + logger.error(traceback.format_exc()) + self.vnf_operate_failed_handle(e.message) def apply_grant(self): vdus = VmInstModel.objects.filter(instid=self.nf_inst_id) - apply_result = grant_resource(data=self.data, nf_inst_id=self.nf_inst_id, job_id=self.job_id, - grant_type=self.grant_type, vdus=vdus) + apply_result = grant_resource(data=self.data, + nf_inst_id=self.nf_inst_id, + job_id=self.job_id, + grant_type=self.grant_type, + vdus=vdus) logger.info("Grant resource, response: %s" % apply_result) JobUtil.add_job_status(self.job_id, 20, 'Nf Operate grant_resource finish') @@ -89,7 +113,11 @@ class OperateVnf(Thread): def operate_resource(self): logger.info('Operate resource begin') - adaptor.operate_vim_res(self.inst_resource, self.changeStateTo, self.stopType, self.gracefulStopTimeout, self.do_notify_op) + adaptor.operate_vim_res(self.inst_resource, + self.changeStateTo, + self.stopType, + self.gracefulStopTimeout, + self.do_notify_op) logger.info('Operate resource complete') def lcm_notify(self, status, opState, err=None): @@ -100,7 +128,11 @@ class OperateVnf(Thread): def vnf_operate_failed_handle(self, error_msg): logger.error('VNF Operation failed, detail message: %s' % error_msg) - NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status=VNF_STATUS.FAILED, lastuptime=now_time()) + NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update( + status=VNF_STATUS.FAILED, + lastuptime=now_time() + ) + self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, error_msg) JobUtil.add_job_status(self.job_id, 255, error_msg) def do_notify_op(self, status, resid): |