Debian Codegraph @

octavia_tempest_plugin/services/load_balancer/v2/member_client.py

raw symbols SCIP
1 # Copyright 2018 GoDaddy
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from oslo_log import log as logging
16 from oslo_serialization import jsonutils
17 from tempest import config
18
19 from octavia_tempest_plugin.common.decorators import skip_if_not_implemented
20 from octavia_tempest_plugin.services.load_balancer.v2 import base_client
21 from octavia_tempest_plugin.services.load_balancer.v2 import pool_client
22
23 CONF = config.CONF
24 LOG = logging.getLogger(__name__)
25 Unset = base_client.Unset
26
27
28 class MemberClient(base_client.BaseLBaaSClient):
29
30 root_tag = 'member'
31 list_root_tag = 'members'
32
33 def __init__(self, *args, **kwargs):
34 super(MemberClient, self).__init__(*args, **kwargs)
35 pool_list_root_tag = pool_client.PoolClient.list_root_tag
36 # /v2.0/lbaas/pools/<POOL_UUID>/members
37 self.uri = "{pool_base_uri}/{parent}/{object}".format(
38 pool_base_uri=self.base_uri.format(object=pool_list_root_tag),
39 parent="{parent}",
40 object=self.list_root_tag
41 )
42
43 @skip_if_not_implemented
44 def create_member(self, pool_id, address, protocol_port,
45 name=Unset, tags=Unset, admin_state_up=Unset,
46 weight=Unset,
47 backup=Unset, subnet_id=Unset, monitor_address=Unset,
48 monitor_port=Unset, return_object_only=True):
49 """Create a member.
50
51 :param pool_id: The ID of the pool where the member will live.
52 :param address: The IP address of the resource.
53 :param protocol_port: The protocol port number for the resource.
54 :param name: Human-readable name of the resource.
55 :param tags: Human-readable tags of the resource.
56 :param admin_state_up: The administrative state of the resource, which
57 is up (true) or down (false).
58 :param weight: The weight of a member determines the portion of
59 requests or connections it services compared to the
60 other members of the pool.
61 :param backup: Is the member a backup?
62 :param subnet_id: The subnet ID which the member service
63 is accessible from
64 :param monitor_address: An alternate IP address used for health
65 monitoring a backend member.
66 :param monitor_port: An alternate protocol port used for health
67 monitoring a backend member.
68 :param return_object_only: If True, the response returns the object
69 inside the root tag. False returns the full
70 response from the API.
71 :raises AssertionError: if the expected_code isn't a valid http success
72 response code
73 :raises BadRequest: If a 400 response code is received
74 :raises Conflict: If a 409 response code is received
75 :raises Forbidden: If a 403 response code is received
76 :raises Gone: If a 410 response code is received
77 :raises InvalidContentType: If a 415 response code is received
78 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
79 :raises InvalidHttpSuccessCode: if the read code isn't an expected
80 http success code
81 :raises NotFound: If a 404 response code is received
82 :raises NotImplemented: If a 501 response code is received
83 :raises OverLimit: If a 413 response code is received and over_limit is
84 not in the response body
85 :raises RateLimitExceeded: If a 413 response code is received and
86 over_limit is in the response body
87 :raises ServerFault: If a 500 response code is received
88 :raises Unauthorized: If a 401 response code is received
89 :raises UnexpectedContentType: If the content-type of the response
90 isn't an expect type
91 :raises UnexpectedResponseCode: If a response code above 400 is
92 received and it doesn't fall into any
93 of the handled checks
94 :raises UnprocessableEntity: If a 422 response code is received and
95 couldn't be parsed
96 :returns: A member object.
97 """
98 kwargs = {arg: value for arg, value in locals().items()
99 if arg != 'self' and value is not Unset}
100 kwargs['parent_id'] = kwargs.pop('pool_id')
101 return self._create_object(**kwargs)
102
103 @skip_if_not_implemented
104 def show_member(self, member_id, pool_id, query_params=None,
105 return_object_only=True):
106 """Get member details.
107
108 :param member_id: The member ID to query.
109 :param pool_id: The ID of the pool where the member lives.
110 :param query_params: The optional query parameters to append to the
111 request. Ex. fields=id&fields=name
112 :param return_object_only: If True, the response returns the object
113 inside the root tag. False returns the full
114 response from the API.
115 :raises AssertionError: if the expected_code isn't a valid http success
116 response code
117 :raises BadRequest: If a 400 response code is received
118 :raises Conflict: If a 409 response code is received
119 :raises Forbidden: If a 403 response code is received
120 :raises Gone: If a 410 response code is received
121 :raises InvalidContentType: If a 415 response code is received
122 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
123 :raises InvalidHttpSuccessCode: if the read code isn't an expected
124 http success code
125 :raises NotFound: If a 404 response code is received
126 :raises NotImplemented: If a 501 response code is received
127 :raises OverLimit: If a 413 response code is received and over_limit is
128 not in the response body
129 :raises RateLimitExceeded: If a 413 response code is received and
130 over_limit is in the response body
131 :raises ServerFault: If a 500 response code is received
132 :raises Unauthorized: If a 401 response code is received
133 :raises UnexpectedContentType: If the content-type of the response
134 isn't an expect type
135 :raises UnexpectedResponseCode: If a response code above 400 is
136 received and it doesn't fall into any
137 of the handled checks
138 :raises UnprocessableEntity: If a 422 response code is received and
139 couldn't be parsed
140 :returns: A member object.
141 """
142 return self._show_object(obj_id=member_id,
143 parent_id=pool_id,
144 query_params=query_params,
145 return_object_only=return_object_only)
146
147 @skip_if_not_implemented
148 def list_members(self, pool_id, query_params=None,
149 return_object_only=True):
150 """Get a list of member objects.
151
152 :param pool_id: The ID of the pool where the members live.
153 :param query_params: The optional query parameters to append to the
154 request. Ex. fields=id&fields=name
155 :param return_object_only: If True, the response returns the object
156 inside the root tag. False returns the full
157 response from the API.
158 :raises AssertionError: if the expected_code isn't a valid http success
159 response code
160 :raises BadRequest: If a 400 response code is received
161 :raises Conflict: If a 409 response code is received
162 :raises Forbidden: If a 403 response code is received
163 :raises Gone: If a 410 response code is received
164 :raises InvalidContentType: If a 415 response code is received
165 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
166 :raises InvalidHttpSuccessCode: if the read code isn't an expected
167 http success code
168 :raises NotFound: If a 404 response code is received
169 :raises NotImplemented: If a 501 response code is received
170 :raises OverLimit: If a 413 response code is received and over_limit is
171 not in the response body
172 :raises RateLimitExceeded: If a 413 response code is received and
173 over_limit is in the response body
174 :raises ServerFault: If a 500 response code is received
175 :raises Unauthorized: If a 401 response code is received
176 :raises UnexpectedContentType: If the content-type of the response
177 isn't an expect type
178 :raises UnexpectedResponseCode: If a response code above 400 is
179 received and it doesn't fall into any
180 of the handled checks
181 :raises UnprocessableEntity: If a 422 response code is received and
182 couldn't be parsed
183 :returns: A list of member objects.
184 """
185 return self._list_objects(parent_id=pool_id,
186 query_params=query_params,
187 return_object_only=return_object_only)
188
189 @skip_if_not_implemented
190 def update_member(self, member_id, pool_id, name=Unset, tags=Unset,
191 admin_state_up=Unset, weight=Unset, backup=Unset,
192 monitor_address=Unset, monitor_port=Unset,
193 return_object_only=True):
194 """Update a member.
195
196 :param member_id: The member ID to update.
197 :param pool_id: The ID of the pool where the member lives.
198 :param name: Human-readable name of the resource.
199 :param tags: Human-readable tags of the resource.
200 :param admin_state_up: The administrative state of the resource, which
201 is up (true) or down (false).
202 :param weight: The weight of a member determines the portion of
203 requests or connections it services compared to the
204 other members of the pool.
205 :param backup: Is the member a backup?
206 :param monitor_address: An alternate IP address used for health
207 monitoring a backend member.
208 :param monitor_port: An alternate protocol port used for health
209 monitoring a backend member.
210 :param return_object_only: If True, the response returns the object
211 inside the root tag. False returns the full
212 response from the API.
213 :raises AssertionError: if the expected_code isn't a valid http success
214 response code
215 :raises BadRequest: If a 400 response code is received
216 :raises Conflict: If a 409 response code is received
217 :raises Forbidden: If a 403 response code is received
218 :raises Gone: If a 410 response code is received
219 :raises InvalidContentType: If a 415 response code is received
220 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
221 :raises InvalidHttpSuccessCode: if the read code isn't an expected
222 http success code
223 :raises NotFound: If a 404 response code is received
224 :raises NotImplemented: If a 501 response code is received
225 :raises OverLimit: If a 413 response code is received and over_limit is
226 not in the response body
227 :raises RateLimitExceeded: If a 413 response code is received and
228 over_limit is in the response body
229 :raises ServerFault: If a 500 response code is received
230 :raises Unauthorized: If a 401 response code is received
231 :raises UnexpectedContentType: If the content-type of the response
232 isn't an expect type
233 :raises UnexpectedResponseCode: If a response code above 400 is
234 received and it doesn't fall into any
235 of the handled checks
236 :raises UnprocessableEntity: If a 422 response code is received and
237 couldn't be parsed
238 :returns: A member object.
239 """
240 kwargs = {arg: value for arg, value in locals().items()
241 if arg != 'self' and value is not Unset}
242 kwargs['obj_id'] = kwargs.pop('member_id')
243 kwargs['parent_id'] = kwargs.pop('pool_id')
244 return self._update_object(**kwargs)
245
246 @skip_if_not_implemented
247 def update_members(self, pool_id, members_list):
248 """Batch update all members on a pool.
249
250 :param pool_id: The ID of the pool where the members live.
251 :param members_list: The list of members to enforce on the pool.
252 :raises AssertionError: if the expected_code isn't a valid http success
253 response code
254 :raises BadRequest: If a 400 response code is received
255 :raises Conflict: If a 409 response code is received
256 :raises Forbidden: If a 403 response code is received
257 :raises Gone: If a 410 response code is received
258 :raises InvalidContentType: If a 415 response code is received
259 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
260 :raises InvalidHttpSuccessCode: if the read code isn't an expected
261 http success code
262 :raises NotFound: If a 404 response code is received
263 :raises NotImplemented: If a 501 response code is received
264 :raises OverLimit: If a 413 response code is received and over_limit is
265 not in the response body
266 :raises RateLimitExceeded: If a 413 response code is received and
267 over_limit is in the response body
268 :raises ServerFault: If a 500 response code is received
269 :raises Unauthorized: If a 401 response code is received
270 :raises UnexpectedContentType: If the content-type of the response
271 isn't an expect type
272 :raises UnexpectedResponseCode: If a response code above 400 is
273 received and it doesn't fall into any
274 of the handled checks
275 :raises UnprocessableEntity: If a 422 response code is received and
276 couldn't be parsed
277 :returns: A member object.
278 """
279 obj_dict = {self.list_root_tag: members_list}
280 request_uri = self.uri.format(parent=pool_id)
281
282 response, body = self.put(request_uri, jsonutils.dumps(obj_dict))
283 self.expected_success(202, response.status)
284 return
285
286 @skip_if_not_implemented
287 def delete_member(self, member_id, pool_id, ignore_errors=False):
288 """Delete a member.
289
290 :param member_id: The member ID to delete.
291 :param pool_id: The ID of the pool where the member lives.
292 :param ignore_errors: True if errors should be ignored.
293 :raises AssertionError: if the expected_code isn't a valid http success
294 response code
295 :raises BadRequest: If a 400 response code is received
296 :raises Conflict: If a 409 response code is received
297 :raises Forbidden: If a 403 response code is received
298 :raises Gone: If a 410 response code is received
299 :raises InvalidContentType: If a 415 response code is received
300 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
301 :raises InvalidHttpSuccessCode: if the read code isn't an expected
302 http success code
303 :raises NotFound: If a 404 response code is received
304 :raises NotImplemented: If a 501 response code is received
305 :raises OverLimit: If a 413 response code is received and over_limit is
306 not in the response body
307 :raises RateLimitExceeded: If a 413 response code is received and
308 over_limit is in the response body
309 :raises ServerFault: If a 500 response code is received
310 :raises Unauthorized: If a 401 response code is received
311 :raises UnexpectedContentType: If the content-type of the response
312 isn't an expect type
313 :raises UnexpectedResponseCode: If a response code above 400 is
314 received and it doesn't fall into any
315 of the handled checks
316 :raises UnprocessableEntity: If a 422 response code is received and
317 couldn't be parsed
318 :returns: None if ignore_errors is True, the response status code
319 if not.
320 """
321 return self._delete_obj(obj_id=member_id,
322 parent_id=pool_id,
323 ignore_errors=ignore_errors)
324
325 def cleanup_member(self, member_id, pool_id, lb_client=None, lb_id=None):
326 kwargs = {arg: value for arg, value in locals().items()
327 if arg != 'self' and value is not Unset}
328 kwargs['obj_id'] = kwargs.pop('member_id')
329 kwargs['parent_id'] = kwargs.pop('pool_id')
330 return self._cleanup_obj(**kwargs)
331
332 def is_resource_deleted(self, id):
333 # Trying to implement this for members would be impossible, because
334 # they are sub-objects that can't be referenced directly, and this is
335 # used internally in tempest where we have no control over passed args
336 raise NotImplementedError()