blob: c141fa798f1498892f89d5cc73b449696192a245 [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
Matthew Treinish684d8992014-01-30 16:27:40 +000027 def __init__(self, username, password, auth_url, tenant_name=None):
Leo Toyodad80b6a02013-05-08 12:15:13 +090028 super(TenantUsagesClientJSON, self).__init__(
Matthew Treinish684d8992014-01-30 16:27:40 +000029 username, password, auth_url, tenant_name)
30 self.service = CONF.compute.catalog_type
Leo Toyodad80b6a02013-05-08 12:15:13 +090031
32 def list_tenant_usages(self, params=None):
33 url = 'os-simple-tenant-usage'
34 if params:
35 url += '?%s' % urllib.urlencode(params)
36
37 resp, body = self.get(url)
38 body = json.loads(body)
39 return resp, body['tenant_usages'][0]
40
41 def get_tenant_usage(self, tenant_id, params=None):
42 url = 'os-simple-tenant-usage/%s' % tenant_id
43 if params:
44 url += '?%s' % urllib.urlencode(params)
45
46 resp, body = self.get(url)
47 body = json.loads(body)
48 return resp, body['tenant_usage']