def put(self, data): """Charge the account.""" # check accountant charge value lacv = int(CONF.limited_accountant_charge_value) if data.value < -lacv or data.value > lacv: raise exception.InvalidChargeValue(value=data.value) try: charge = HOOK.conductor_rpcapi.charge_account( HOOK.context, self._id, **data.as_dict()) except exception.NotAuthorized as e: LOG.error('Fail to charge the account:%s' 'due to not authorization' % self._id) raise exception.NotAuthorized() except Exception as e: LOG.error('Fail to charge the account:%s,' 'charge value: %s' % (self._id, data.value)) raise exception.DBError(reason=e) return models.Charge.from_db_model(charge)
def get_all(self, owed=None, limit=None, offset=None, duration=None): """Get this account.""" policy.check_policy(HOOK.context, "account:all", action="account:all") owed = False if limit and limit < 0: raise exception.InvalidParameterValue(err="Invalid limit") if offset and offset < 0: raise exception.InvalidParameterValue(err="Invalid offset") duration = timeutils.normalize_timedelta(duration) if duration: active_from = timeutils.utcnow() - duration else: active_from = None try: accounts = HOOK.conductor_rpcapi.get_accounts( HOOK.context, owed=owed, limit=limit, offset=offset, active_from=active_from) count = len(accounts) except exception.NotAuthorized as e: LOG.error('Failed to get all accounts') raise exception.NotAuthorized() except Exception as e: LOG.error('Failed to get all accounts') raise exception.DBError(reason=e) accounts = [ models.AdminAccount.transform(**account) for account in accounts ] return models.AdminAccounts.transform(total_count=count, accounts=accounts)
def require_domain_context(context): if not context.is_admin and not context.is_domain_owner: raise exception.NotAuthorized()
def require_admin_context(context): if not context.is_admin: raise exception.NotAuthorized()
def get_endpoint(self): if self.management_url is None: raise exception.NotAuthorized(('Current authorization' 'does not have a known' 'billing management url')) return self.management_url
def get_auth_headers(self, **kwargs): if self.auth_token is None: raise exception.NotAuthorized( 'Current authorization does not have a token') return {'X-Auth-Token': self.auth_token}