blob: 3214053f6a00e4420e56e2efedc49a3e35f2993c [file] [log] [blame]
elajkat23e07472019-07-12 15:21:14 +02001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
songwenping99d6e002021-01-05 03:07:46 +000013from urllib import parse as urllib
14
elajkat23e07472019-07-12 15:21:14 +020015from oslo_serialization import jsonutils as json
elajkat23e07472019-07-12 15:21:14 +020016
17from tempest.lib.common import rest_client
18from tempest.lib.services.placement import base_placement_client
19
20
21class ResourceProvidersClient(base_placement_client.BasePlacementClient):
22 """Client class for resource provider related methods
23
24 This client class aims to support read-only API operations for resource
25 providers. The following resources are supported:
26 * resource providers
27 * resource provider inventories
28 * resource provider aggregates
James Parker92005532021-03-25 22:33:14 -040029 * resource provider usages
elajkat23e07472019-07-12 15:21:14 +020030 """
31
32 def list_resource_providers(self, **params):
33 """List resource providers.
34
35 For full list of available parameters, please refer to the official
36 API reference:
37 https://docs.openstack.org/api-ref/placement/#list-resource-providers
38 """
39 url = '/resource_providers'
40 if params:
41 url += '?%s' % urllib.urlencode(params)
42 resp, body = self.get(url)
43 self.expected_success(200, resp.status)
44 body = json.loads(body)
45 return rest_client.ResponseBody(resp, body)
46
47 def show_resource_provider(self, rp_uuid):
48 """Show resource provider.
49
50 For full list of available parameters, please refer to the official
51 API reference:
52 https://docs.openstack.org/api-ref/placement/#show-resource-provider
53 """
54 url = '/resource_providers/%s' % rp_uuid
55 resp, body = self.get(url)
56 self.expected_success(200, resp.status)
57 body = json.loads(body)
58 return rest_client.ResponseBody(resp, body)
59
60 def list_resource_provider_inventories(self, rp_uuid):
61 """List resource provider inventories.
62
63 For full list of available parameters, please refer to the official
64 API reference:
65 https://docs.openstack.org/api-ref/placement/#list-resource-provider-inventories
66 """
67 url = '/resource_providers/%s/inventories' % rp_uuid
68 resp, body = self.get(url)
69 self.expected_success(200, resp.status)
70 body = json.loads(body)
71 return rest_client.ResponseBody(resp, body)
72
James Parker92005532021-03-25 22:33:14 -040073 def list_resource_provider_usages(self, rp_uuid):
74 """List resource provider usages.
75
76 For full list of available parameters, please refer to the official
77 API reference:
78 https://docs.openstack.org/api-ref/placement/#list-resource-provider-usages
79 """
80 url = '/resource_providers/%s/usages' % rp_uuid
81 resp, body = self.get(url)
82 self.expected_success(200, resp.status)
83 body = json.loads(body)
84 return rest_client.ResponseBody(resp, body)
85
elajkat23e07472019-07-12 15:21:14 +020086 def list_resource_provider_aggregates(self, rp_uuid):
87 """List resource provider aggregates.
88
89 For full list of available parameters, please refer to the official
90 API reference:
91 https://docs.openstack.org/api-ref/placement/#list-resource-provider-aggregates
92 """
93 url = '/resource_providers/%s/aggregates' % rp_uuid
94 resp, body = self.get(url)
95 self.expected_success(200, resp.status)
96 body = json.loads(body)
97 return rest_client.ResponseBody(resp, body)
wanglbj5ffc28f2020-12-18 10:49:37 +080098
99 def update_resource_providers_inventories(self, rp_uuid, **kwargs):
100 """Update resource providers inventories.
101
102 For full list of available parameters, please refer to the official
103 API reference:
104 https://docs.openstack.org/api-ref/placement/#update-resource-provider-inventories
105 """
106 url = '/resource_providers/{}/inventories'.format(rp_uuid)
107 data = json.dumps(kwargs)
108 resp, body = self.put(url, data)
109 self.expected_success(200, resp.status)
110 body = json.loads(body)
111 return rest_client.ResponseBody(resp, body)
112
113 def delete_resource_providers_inventories(self, rp_uuid):
114 """Delete resource providers inventories.
115
116 For full list of available parameters, please refer to the official
117 API reference:
118 https://docs.openstack.org/api-ref/placement/#delete-resource-provider-inventories
119 """
120 url = '/resource_providers/{}/inventories'.format(rp_uuid)
121 resp, body = self.delete(url)
122 self.expected_success(204, resp.status)
123 return rest_client.ResponseBody(resp, body)