diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-07-09 15:20:49 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-07-09 15:27:18 +0800 |
commit | f2e52aa4efb15e1f94506710528d6f47d21348d6 (patch) | |
tree | 79df37d9ffc17cba54651fc58e53db8b20dad8c8 /lcm | |
parent | 87ba2f52d9e649b48ca76be0d53f53010613709c (diff) |
Refactor codes for notify util
Change-Id: I6ba2438dd16393e8f4f20f723389090da7d8877a
Issue-ID: VFC-1429
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/pub/utils/notificationsutil.py | 40 |
1 files 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) |