Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [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 | from oslo_serialization import jsonutils as json |
| 17 | from six.moves.urllib import parse as urllib |
| 18 | |
| 19 | from tempest.lib.api_schema.response.compute.v2_1 import tenant_usages |
| 20 | from tempest.lib.common import rest_client |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 21 | from tempest.lib.services.compute import base_compute_client |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 22 | |
| 23 | |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 24 | class TenantUsagesClient(base_compute_client.BaseComputeClient): |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 25 | |
| 26 | def list_tenant_usages(self, **params): |
zhufl | 29ea88b | 2016-11-16 14:01:05 +0800 | [diff] [blame] | 27 | """List Tenant Usage For All Tenants. |
| 28 | |
| 29 | For a full list of available parameters, please refer to the official |
| 30 | API reference: |
zhufl | 6ea5f8b | 2017-04-05 17:34:08 +0800 | [diff] [blame] | 31 | https://developer.openstack.org/api-ref/compute/#list-tenant-usage-statistics-for-all-tenants |
zhufl | 29ea88b | 2016-11-16 14:01:05 +0800 | [diff] [blame] | 32 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 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) |
| 39 | self.validate_response(tenant_usages.list_tenant_usage, resp, body) |
| 40 | return rest_client.ResponseBody(resp, body) |
| 41 | |
| 42 | def show_tenant_usage(self, tenant_id, **params): |
zhufl | 29ea88b | 2016-11-16 14:01:05 +0800 | [diff] [blame] | 43 | """Show Usage Details For Tenant. |
| 44 | |
| 45 | For a full list of available parameters, please refer to the official |
| 46 | API reference: |
zhufl | 6ea5f8b | 2017-04-05 17:34:08 +0800 | [diff] [blame] | 47 | https://developer.openstack.org/api-ref/compute/#show-usage-statistics-for-tenant |
zhufl | 29ea88b | 2016-11-16 14:01:05 +0800 | [diff] [blame] | 48 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 49 | url = 'os-simple-tenant-usage/%s' % tenant_id |
| 50 | if params: |
| 51 | url += '?%s' % urllib.urlencode(params) |
| 52 | |
| 53 | resp, body = self.get(url) |
| 54 | body = json.loads(body) |
| 55 | self.validate_response(tenant_usages.get_tenant_usage, resp, body) |
| 56 | return rest_client.ResponseBody(resp, body) |