From f2e52aa4efb15e1f94506710528d6f47d21348d6 Mon Sep 17 00:00:00 2001 From: fujinhua Date: Tue, 9 Jul 2019 15:20:49 +0800 Subject: Refactor codes for notify util Change-Id: I6ba2438dd16393e8f4f20f723389090da7d8877a Issue-ID: VFC-1429 Signed-off-by: fujinhua --- lcm/lcm/pub/utils/notificationsutil.py | 40 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lcm/lcm/pub/utils/notificationsutil.py b/lcm/lcm/pub/utils/notificationsutil.py index 2eb820fe..8a38fd62 100644 --- a/lcm/lcm/pub/utils/notificationsutil.py +++ b/lcm/lcm/pub/utils/notificationsutil.py @@ -22,24 +22,24 @@ from rest_framework import status from lcm.nf import const from lcm.pub.database.models import SubscriptionModel -from lcm.pub.database.models import ( - VmInstModel, NetworkInstModel, - PortInstModel, StorageInstModel, VNFCInstModel -) +from lcm.pub.database.models import VmInstModel +from lcm.pub.database.models import NetworkInstModel +from lcm.pub.database.models import PortInstModel +from lcm.pub.database.models import StorageInstModel +from lcm.pub.database.models import VNFCInstModel from lcm.pub.utils.timeutil import now_time from lcm.pub.utils.enumutil import enum logger = logging.getLogger(__name__) -NOTIFY_TYPE = enum(lCM_OP_OCC="VnfLcmOperationOccurrenceNotification", - CREATION="VnfIdentifierCreationNotification", - DELETION="VnfIdentifierDeletionNotification") +NOTIFY_TYPE = enum( + lCM_OP_OCC="VnfLcmOperationOccurrenceNotification", + CREATION="VnfIdentifierCreationNotification", + DELETION="VnfIdentifierDeletionNotification" +) class NotificationsUtil(object): - def __init__(self): - pass - def send_notification(self, notification): logger.info("Send Notifications to the callbackUri") filters = { @@ -72,11 +72,13 @@ class NotificationsUtil(object): username = params.get("userName") password = params.get("password") logger.info("Sending notification to %s", callbackUri) - resp = requests.post(callbackUri, - data=notification, - auth=HTTPBasicAuth(username, password)) + resp = requests.post( + callbackUri, + data=notification, + auth=HTTPBasicAuth(username, password) + ) if resp.status_code != status.HTTP_204_NO_CONTENT: - raise Exception("Notify %s failed: %s" % (callbackUri, resp.text)) + logger.error("Notify %s failed: %s", callbackUri, resp.text) def set_affected_vnfcs(affected_vnfcs, nfinstid, changetype): @@ -207,10 +209,12 @@ def prepare_notification(nfinstid, jobid, operation, operation_state): def prepare_notification_data(nfinstid, jobid, changetype, operation): - data = prepare_notification(nfinstid=nfinstid, - jobid=jobid, - operation=operation, - operation_state=const.OPERATION_STATE_TYPE.COMPLETED) + data = prepare_notification( + nfinstid=nfinstid, + jobid=jobid, + operation=operation, + operation_state=const.OPERATION_STATE_TYPE.COMPLETED + ) set_affected_vnfcs(data['affectedVnfcs'], nfinstid, changetype) set_affected_vls(data['affectedVirtualLinks'], nfinstid, changetype) -- cgit 1.2.3-korg