blob: f8adae7d8ecdcdd63e8719aa618d789336df3008 [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
Eiichi Aikawade0e69e2014-03-20 19:49:55 +090019from tempest.api_schema.compute.v2 import tenant_usages as schema
Haiwei Xuab924622014-03-05 04:33:51 +090020from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000021from tempest import config
22
23CONF = config.CONF
Leo Toyodad80b6a02013-05-08 12:15:13 +090024
25
Haiwei Xuab924622014-03-05 04:33:51 +090026class TenantUsagesClientJSON(rest_client.RestClient):
Leo Toyodad80b6a02013-05-08 12:15:13 +090027
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000028 def __init__(self, auth_provider):
29 super(TenantUsagesClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000030 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)
Eiichi Aikawade0e69e2014-03-20 19:49:55 +090039 self.validate_response(schema.list_tenant, resp, body)
Leo Toyodad80b6a02013-05-08 12:15:13 +090040 return resp, body['tenant_usages'][0]
41
42 def get_tenant_usage(self, tenant_id, params=None):
43 url = 'os-simple-tenant-usage/%s' % tenant_id
44 if params:
45 url += '?%s' % urllib.urlencode(params)
46
47 resp, body = self.get(url)
48 body = json.loads(body)
Eiichi Aikawade0e69e2014-03-20 19:49:55 +090049 self.validate_response(schema.get_tenant, resp, body)
Leo Toyodad80b6a02013-05-08 12:15:13 +090050 return resp, body['tenant_usage']