blob: ff6e7a2db8895b7adc398a9d3eef7f63d478740c [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
ghanshyamaa93b4b2015-03-20 11:03:44 +090019from tempest.api_schema.response.compute.v2_1 import tenant_usages as schema
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000020from tempest.common import service_client
Leo Toyodad80b6a02013-05-08 12:15:13 +090021
22
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000023class TenantUsagesClientJSON(service_client.ServiceClient):
Leo Toyodad80b6a02013-05-08 12:15:13 +090024
25 def list_tenant_usages(self, params=None):
26 url = 'os-simple-tenant-usage'
27 if params:
28 url += '?%s' % urllib.urlencode(params)
29
30 resp, body = self.get(url)
31 body = json.loads(body)
Eiichi Aikawade0e69e2014-03-20 19:49:55 +090032 self.validate_response(schema.list_tenant, resp, body)
David Kranz5cf4ba42015-02-10 14:00:50 -050033 return service_client.ResponseBodyList(resp, body['tenant_usages'][0])
Leo Toyodad80b6a02013-05-08 12:15:13 +090034
35 def get_tenant_usage(self, tenant_id, params=None):
36 url = 'os-simple-tenant-usage/%s' % tenant_id
37 if params:
38 url += '?%s' % urllib.urlencode(params)
39
40 resp, body = self.get(url)
41 body = json.loads(body)
Eiichi Aikawade0e69e2014-03-20 19:49:55 +090042 self.validate_response(schema.get_tenant, resp, body)
David Kranz5cf4ba42015-02-10 14:00:50 -050043 return service_client.ResponseBodyList(resp, body['tenant_usage'])