blob: b14fa9bc2c6607393d179cd017da8161441ff199 [file] [log] [blame]
Leo Toyodad80b6a02013-05-08 12:15:13 +09001# Copyright 2013 NEC Corporation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import json
17import urllib
18
19from tempest.common.rest_client import RestClient
Matthew Treinish684d8992014-01-30 16:27:40 +000020from tempest import config
21
22CONF = config.CONF
Leo Toyodad80b6a02013-05-08 12:15:13 +090023
24
25class TenantUsagesClientJSON(RestClient):
26
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000027 def __init__(self, auth_provider):
28 super(TenantUsagesClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000029 self.service = CONF.compute.catalog_type
Leo Toyodad80b6a02013-05-08 12:15:13 +090030
31 def list_tenant_usages(self, params=None):
32 url = 'os-simple-tenant-usage'
33 if params:
34 url += '?%s' % urllib.urlencode(params)
35
36 resp, body = self.get(url)
37 body = json.loads(body)
38 return resp, body['tenant_usages'][0]
39
40 def get_tenant_usage(self, tenant_id, params=None):
41 url = 'os-simple-tenant-usage/%s' % tenant_id
42 if params:
43 url += '?%s' % urllib.urlencode(params)
44
45 resp, body = self.get(url)
46 body = json.loads(body)
47 return resp, body['tenant_usage']