Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 1 | # 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 | |
| 16 | import json |
| 17 | import urllib |
| 18 | |
ghanshyam | aa93b4b | 2015-03-20 11:03:44 +0900 | [diff] [blame] | 19 | from tempest.api_schema.response.compute.v2_1 import tenant_usages as schema |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 20 | from tempest.common import service_client |
Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 21 | |
| 22 | |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 23 | class TenantUsagesClientJSON(service_client.ServiceClient): |
Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 24 | |
| 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 Aikawa | de0e69e | 2014-03-20 19:49:55 +0900 | [diff] [blame] | 32 | self.validate_response(schema.list_tenant, resp, body) |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 33 | return service_client.ResponseBodyList(resp, body['tenant_usages'][0]) |
Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 34 | |
| 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 Aikawa | de0e69e | 2014-03-20 19:49:55 +0900 | [diff] [blame] | 42 | self.validate_response(schema.get_tenant, resp, body) |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 43 | return service_client.ResponseBodyList(resp, body['tenant_usage']) |