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 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 16 | from oslo_serialization import jsonutils as json |
Matthew Treinish | 8912814 | 2015-04-23 10:44:30 -0400 | [diff] [blame] | 17 | from six.moves.urllib import parse as urllib |
Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 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 | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 23 | class TenantUsagesClient(service_client.ServiceClient): |
Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 24 | |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 25 | def list_tenant_usages(self, **params): |
Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 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) |
ghanshyam | 59869d0 | 2015-04-22 17:23:08 +0900 | [diff] [blame] | 32 | self.validate_response(schema.list_tenant_usage, 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 | |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 35 | def show_tenant_usage(self, tenant_id, **params): |
Leo Toyoda | d80b6a0 | 2013-05-08 12:15:13 +0900 | [diff] [blame] | 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) |
ghanshyam | 59869d0 | 2015-04-22 17:23:08 +0900 | [diff] [blame] | 42 | self.validate_response(schema.get_tenant_usage, resp, body) |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 43 | return service_client.ResponseBodyList(resp, body['tenant_usage']) |