- if call_res:
- reg = uow.configurations.get(reg_data['configurationId'])
- if reg is None:
- return
- reg.status = RegistrationStatusEnum.NOTIFIED
- logger.debug('Updating Configurations: {}'.format(
- reg.configurationId))
- uow.configurations.update(reg)
- uow.commit()
-
-
-# def retry(fun, max_tries=2):
-# for i in range(max_tries):
-# try:
-# time.sleep(5*i)
-# # await asyncio.sleep(5*i)
-# res = fun()
-# logger.debug('retry function result: {}'.format(res))
-# return res
-# except Exception:
-# continue
-
-
-@retry((ConnectionRefusedError), tries=2, delay=2)
-def call_smo(reg_data: dict):
+ if call_res is True:
+ logger.info('Register to smo success response')
+ else:
+ raise RegIMSToSMOExp('Register o2ims to SMO failed')
+ # TODO: record the result for the smo register
+
+
+def _notify_ocloud(uow, data, ocloud_dict):
+ ref = api_monitoring_base + inventory_api_version
+ msg = Message2SMO(
+ eventtype=data.notificationEventType, id=data.id,
+ ref=ref, updatetime=data.updatetime)
+ ocloud_dict.pop('globalCloudId')
+ subs = uow.subscriptions.list()
+ for sub in subs:
+ sub_data = sub.serialize()
+ logger.debug('Subscription: {}'.format(sub_data['subscriptionId']))
+ filters = handle_filter(sub_data['filter'], 'CloudInfo')
+ if not filters:
+ callback_smo(sub, msg, ocloud_dict)
+ continue
+ filter_hit = False
+ for filter in filters:
+ try:
+ args = gen_orm_filter(cloud.Ocloud, filter)
+ except KeyError:
+ logger.warning(
+ 'Subscription {} filter {} has wrong attribute '
+ 'name or value. Ignore the filter.'.format(
+ sub_data['subscriptionId'],
+ sub_data['filter']))
+ continue
+ if len(args) == 0 and 'objectType' in filter:
+ filter_hit = True
+ break
+ args.append(cloud.Ocloud.oCloudId == data.id)
+ ret = uow.oclouds.list(*args)
+ if ret.count() > 0:
+ filter_hit = True
+ break
+ if filter_hit:
+ logger.info('Subscription {} filter hit, skip oCloud {}.'
+ .format(sub_data['subscriptionId'], data.id))
+ else:
+ callback_smo(sub, msg, ocloud_dict)
+
+
+def call_smo(notifications: AbstractNotifications, reg_data: dict):
+ smo_token = conf.DEFAULT.smo_token_data
+ smo_token_info = {
+ 'iss': 'o2ims',
+ 'aud': 'smo',
+ 'smo_token_payload': smo_token,
+ 'smo_token_type': 'jwt',
+ 'smo_token_expiration': '',
+ 'smo_token_algo': 'RS256'
+ }
+