def user_delete(self, cnxt, user_id): """Delete a specify user according to the notification.""" LOG.info(_LI('Deleging user: %s'), user_id) user = user_mod.User.load(cnxt, user_id=user_id) if user.status in [user.ACTIVE, user.WARNING]: LOG.error(_LE("User (%s) is in use, can not delete."), user_id) return user_mod.User.delete(cnxt, user_id=user_id) bilean_scheduler.notify(bilean_scheduler.DELETE_JOBS, user=user.to_dict())
def user_recharge(self, cnxt, user_id, value, recharge_type=None, timestamp=None, metadata=None): """Do recharge for specify user.""" try: user = user_mod.User.load(cnxt, user_id=user_id) except exception.UserNotFound as ex: raise exception.BileanBadRequest(msg=six.text_type(ex)) recharge_type = recharge_type or consts.SELF_RECHARGE timestamp = timestamp or timeutils.utcnow() metadata = metadata or {} user.do_recharge(cnxt, value, recharge_type=recharge_type, timestamp=timestamp, metadata=metadata) # As user has been updated, the billing job for the user # should to be updated too. bilean_scheduler.notify(bilean_scheduler.UPDATE_JOBS, user=user.to_dict()) return user.to_dict()
def execute(self, user_obj, **kwargs): res = bilean_scheduler.notify(bilean_scheduler.UPDATE_JOBS, user=user_obj.to_dict()) if not res: LOG.error(_LE("Error when updating user jobs: %s"), user_obj.id) raise