blob: 72fcde231cffb95db56cc943b22187f3e2766ea6 [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
Matthew Treinish21905512015-07-13 10:33:35 -040016from oslo_serialization import jsonutils as json
Matthew Treinish89128142015-04-23 10:44:30 -040017from six.moves.urllib import parse as urllib
Leo Toyodad80b6a02013-05-08 12:15:13 +090018
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 Ohmichia6287072015-07-02 02:43:15 +000023class TenantUsagesClient(service_client.ServiceClient):
Leo Toyodad80b6a02013-05-08 12:15:13 +090024
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000025 def list_tenant_usages(self, **params):
Leo Toyodad80b6a02013-05-08 12:15:13 +090026 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)
ghanshyam59869d02015-04-22 17:23:08 +090032 self.validate_response(schema.list_tenant_usage, 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
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000035 def show_tenant_usage(self, tenant_id, **params):
Leo Toyodad80b6a02013-05-08 12:15:13 +090036 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)
ghanshyam59869d02015-04-22 17:23:08 +090042 self.validate_response(schema.get_tenant_usage, resp, body)
David Kranz5cf4ba42015-02-10 14:00:50 -050043 return service_client.ResponseBodyList(resp, body['tenant_usage'])