Debian Codegraph @

octavia_tempest_plugin/services/load_balancer/v2/loadbalancer_client.py

raw symbols SCIP
1 # Copyright 2017 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
16 from oslo_serialization import jsonutils
17
18 from tempest import config
19
20 from octavia_tempest_plugin.common.decorators import skip_if_not_implemented
21 from octavia_tempest_plugin.services.load_balancer.v2 import base_client
22
23 CONF = config.CONF
24 Unset = base_client.Unset
25
26
27 class LoadbalancerClient(base_client.BaseLBaaSClient):
28
29 root_tag = 'loadbalancer'
30 list_root_tag = 'loadbalancers'
31
32 def __init__(self, auth_provider, service, region, **kwargs):
33 super(LoadbalancerClient, self).__init__(auth_provider, service,
34 region, **kwargs)
35 self.timeout = CONF.load_balancer.lb_build_timeout
36 self.build_interval = CONF.load_balancer.lb_build_interval
37
38 @skip_if_not_implemented
39 def create_loadbalancer(self, name=Unset, description=Unset,
40 admin_state_up=Unset, flavor_id=Unset,
41 listeners=Unset, project_id=Unset, provider=Unset,
42 vip_address=Unset, vip_network_id=Unset,
43 vip_port_id=Unset, vip_qos_policy_id=Unset,
44 vip_subnet_id=Unset, return_object_only=True,
45 tags=Unset):
46 """Create a loadbalancer.
47
48 :param name: Human-readable name of the resource.
49 :param description: A human-readable description for the resource.
50 :param admin_state_up: The administrative state of the resource, which
51 is up (true) or down (false).
52 :param flavor: The loadbalancer flavor ID.
53 :param listeners: A list of listner dictionaries.
54 :param project_id: The ID of the project owning this resource.
55 :param provider: Provider name for the loadbalancer.
56 :param vip_address: The IP address of the Virtual IP (VIP).
57 :param vip_network_id: The ID of the network for the Virtual IP (VIP).
58 :param vip_port_id: The ID of the Virtual IP (VIP) port.
59 :param vip_qos_policy_id: The ID of the QoS Policy which will apply to
60 the Virtual IP (VIP).
61 :param vip_subnet_id: The ID of the subnet for the Virtual IP (VIP).
62 :param tags: A human-readable tags of the resource.
63 :param return_object_only: If True, the response returns the object
64 inside the root tag. False returns the full
65 response from the API.
66 :raises AssertionError: if the expected_code isn't a valid http success
67 response code
68 :raises BadRequest: If a 400 response code is received
69 :raises Conflict: If a 409 response code is received
70 :raises Forbidden: If a 403 response code is received
71 :raises Gone: If a 410 response code is received
72 :raises InvalidContentType: If a 415 response code is received
73 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
74 :raises InvalidHttpSuccessCode: if the read code isn't an expected
75 http success code
76 :raises NotFound: If a 404 response code is received
77 :raises NotImplemented: If a 501 response code is received
78 :raises OverLimit: If a 413 response code is received and over_limit is
79 not in the response body
80 :raises RateLimitExceeded: If a 413 response code is received and
81 over_limit is in the response body
82 :raises ServerFault: If a 500 response code is received
83 :raises Unauthorized: If a 401 response code is received
84 :raises UnexpectedContentType: If the content-type of the response
85 isn't an expect type
86 :raises UnexpectedResponseCode: If a response code above 400 is
87 received and it doesn't fall into any
88 of the handled checks
89 :raises UnprocessableEntity: If a 422 response code is received and
90 couldn't be parsed
91 :returns: A loadbalancer object.
92 """
93 kwargs = {arg: value for arg, value in locals().items()
94 if arg != 'self' and value is not Unset}
95 return self._create_object(**kwargs)
96
97 @skip_if_not_implemented
98 def show_loadbalancer(self, lb_id, query_params=None,
99 return_object_only=True):
100 """Get loadbalancer details.
101
102 :param lb_id: The loadbalancer ID to query.
103 :param query_params: The optional query parameters to append to the
104 request. Ex. fields=id&fields=name
105 :param return_object_only: If True, the response returns the object
106 inside the root tag. False returns the full
107 response from the API.
108 :raises AssertionError: if the expected_code isn't a valid http success
109 response code
110 :raises BadRequest: If a 400 response code is received
111 :raises Conflict: If a 409 response code is received
112 :raises Forbidden: If a 403 response code is received
113 :raises Gone: If a 410 response code is received
114 :raises InvalidContentType: If a 415 response code is received
115 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
116 :raises InvalidHttpSuccessCode: if the read code isn't an expected
117 http success code
118 :raises NotFound: If a 404 response code is received
119 :raises NotImplemented: If a 501 response code is received
120 :raises OverLimit: If a 413 response code is received and over_limit is
121 not in the response body
122 :raises RateLimitExceeded: If a 413 response code is received and
123 over_limit is in the response body
124 :raises ServerFault: If a 500 response code is received
125 :raises Unauthorized: If a 401 response code is received
126 :raises UnexpectedContentType: If the content-type of the response
127 isn't an expect type
128 :raises UnexpectedResponseCode: If a response code above 400 is
129 received and it doesn't fall into any
130 of the handled checks
131 :raises UnprocessableEntity: If a 422 response code is received and
132 couldn't be parsed
133 :returns: A loadbalancer object.
134 """
135 return self._show_object(obj_id=lb_id,
136 query_params=query_params,
137 return_object_only=return_object_only)
138
139 @skip_if_not_implemented
140 def list_loadbalancers(self, query_params=None, return_object_only=True):
141 """Get a list of loadbalancer objects.
142
143 :param query_params: The optional query parameters to append to the
144 request. Ex. fields=id&fields=name
145 :param return_object_only: If True, the response returns the object
146 inside the root tag. False returns the full
147 response from the API.
148 :raises AssertionError: if the expected_code isn't a valid http success
149 response code
150 :raises BadRequest: If a 400 response code is received
151 :raises Conflict: If a 409 response code is received
152 :raises Forbidden: If a 403 response code is received
153 :raises Gone: If a 410 response code is received
154 :raises InvalidContentType: If a 415 response code is received
155 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
156 :raises InvalidHttpSuccessCode: if the read code isn't an expected
157 http success code
158 :raises NotFound: If a 404 response code is received
159 :raises NotImplemented: If a 501 response code is received
160 :raises OverLimit: If a 413 response code is received and over_limit is
161 not in the response body
162 :raises RateLimitExceeded: If a 413 response code is received and
163 over_limit is in the response body
164 :raises ServerFault: If a 500 response code is received
165 :raises Unauthorized: If a 401 response code is received
166 :raises UnexpectedContentType: If the content-type of the response
167 isn't an expect type
168 :raises UnexpectedResponseCode: If a response code above 400 is
169 received and it doesn't fall into any
170 of the handled checks
171 :raises UnprocessableEntity: If a 422 response code is received and
172 couldn't be parsed
173 :returns: A list of loadbalancer objects.
174 """
175 return self._list_objects(query_params=query_params,
176 return_object_only=return_object_only)
177
178 @skip_if_not_implemented
179 def update_loadbalancer(self, lb_id, name=Unset, description=Unset,
180 tags=Unset, admin_state_up=Unset,
181 vip_qos_policy_id=Unset,
182 return_object_only=True):
183 """Update a loadbalancer.
184
185 :param lb_id: The loadbalancer ID to update.
186 :param name: Human-readable name of the resource.
187 :param description: A human-readable description for the resource.
188 :param tags: A human-readable tags of the resource.
189 :param admin_state_up: The administrative state of the resource, which
190 is up (true) or down (false).
191 :param vip_qos_policy_id: The ID of the QoS Policy which will apply to
192 the Virtual IP (VIP).
193 :param return_object_only: If True, the response returns the object
194 inside the root tag. False returns the full
195 response from the API.
196 :raises AssertionError: if the expected_code isn't a valid http success
197 response code
198 :raises BadRequest: If a 400 response code is received
199 :raises Conflict: If a 409 response code is received
200 :raises Forbidden: If a 403 response code is received
201 :raises Gone: If a 410 response code is received
202 :raises InvalidContentType: If a 415 response code is received
203 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
204 :raises InvalidHttpSuccessCode: if the read code isn't an expected
205 http success code
206 :raises NotFound: If a 404 response code is received
207 :raises NotImplemented: If a 501 response code is received
208 :raises OverLimit: If a 413 response code is received and over_limit is
209 not in the response body
210 :raises RateLimitExceeded: If a 413 response code is received and
211 over_limit is in the response body
212 :raises ServerFault: If a 500 response code is received
213 :raises Unauthorized: If a 401 response code is received
214 :raises UnexpectedContentType: If the content-type of the response
215 isn't an expect type
216 :raises UnexpectedResponseCode: If a response code above 400 is
217 received and it doesn't fall into any
218 of the handled checks
219 :raises UnprocessableEntity: If a 422 response code is received and
220 couldn't be parsed
221 :returns: A loadbalancer object.
222 """
223 kwargs = {arg: value for arg, value in locals().items()
224 if arg != 'self' and value is not Unset}
225 kwargs['obj_id'] = kwargs.pop('lb_id')
226 return self._update_object(**kwargs)
227
228 @skip_if_not_implemented
229 def delete_loadbalancer(self, lb_id, cascade=False, ignore_errors=False):
230 """Delete a loadbalancer.
231
232 :param lb_id: The loadbalancer ID to delete.
233 :param ignore_errors: True if errors should be ignored.
234 :param cascade: If true will delete all child objects of an
235 object, if that object supports it.
236 :raises AssertionError: if the expected_code isn't a valid http success
237 response code
238 :raises BadRequest: If a 400 response code is received
239 :raises Conflict: If a 409 response code is received
240 :raises Forbidden: If a 403 response code is received
241 :raises Gone: If a 410 response code is received
242 :raises InvalidContentType: If a 415 response code is received
243 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
244 :raises InvalidHttpSuccessCode: if the read code isn't an expected
245 http success code
246 :raises NotFound: If a 404 response code is received
247 :raises NotImplemented: If a 501 response code is received
248 :raises OverLimit: If a 413 response code is received and over_limit is
249 not in the response body
250 :raises RateLimitExceeded: If a 413 response code is received and
251 over_limit is in the response body
252 :raises ServerFault: If a 500 response code is received
253 :raises Unauthorized: If a 401 response code is received
254 :raises UnexpectedContentType: If the content-type of the response
255 isn't an expect type
256 :raises UnexpectedResponseCode: If a response code above 400 is
257 received and it doesn't fall into any
258 of the handled checks
259 :raises UnprocessableEntity: If a 422 response code is received and
260 couldn't be parsed
261 :returns: None if ignore_errors is True, the response status code
262 if not.
263 """
264 return self._delete_obj(obj_id=lb_id,
265 ignore_errors=ignore_errors,
266 cascade=cascade)
267
268 @skip_if_not_implemented
269 def failover_loadbalancer(self, lb_id):
270 """Failover a loadbalancer.
271
272 :param lb_id: The loadbalancer ID to query.
273 :raises AssertionError: if the expected_code isn't a valid http success
274 response code
275 :raises BadRequest: If a 400 response code is received
276 :raises Conflict: If a 409 response code is received
277 :raises Forbidden: If a 403 response code is received
278 :raises Gone: If a 410 response code is received
279 :raises InvalidContentType: If a 415 response code is received
280 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
281 :raises InvalidHttpSuccessCode: if the read code isn't an expected
282 http success code
283 :raises NotFound: If a 404 response code is received
284 :raises NotImplemented: If a 501 response code is received
285 :raises OverLimit: If a 413 response code is received and over_limit is
286 not in the response body
287 :raises RateLimitExceeded: If a 413 response code is received and
288 over_limit is in the response body
289 :raises ServerFault: If a 500 response code is received
290 :raises Unauthorized: If a 401 response code is received
291 :raises UnexpectedContentType: If the content-type of the response
292 isn't an expect type
293 :raises UnexpectedResponseCode: If a response code above 400 is
294 received and it doesn't fall into any
295 of the handled checks
296 :raises UnprocessableEntity: If a 422 response code is received and
297 couldn't be parsed
298 :returns: None
299 """
300 uri = '{0}/{1}/failover'.format(self.uri, lb_id)
301 response, body = self.put(uri, '')
302 self.expected_success(202, response.status)
303 return
304
305 @skip_if_not_implemented
306 def get_loadbalancer_stats(self, lb_id, query_params=None,
307 return_object_only=True):
308 """Get loadbalancer statistics.
309
310 :param lb_id: The loadbalancer ID to query.
311 :param query_params: The optional query parameters to append to the
312 request. Ex. fields=id&fields=name
313 :param return_object_only: If True, the response returns the object
314 inside the root tag. False returns the full
315 response from the API.
316 :raises AssertionError: if the expected_code isn't a valid http success
317 response code
318 :raises BadRequest: If a 400 response code is received
319 :raises Conflict: If a 409 response code is received
320 :raises Forbidden: If a 403 response code is received
321 :raises Gone: If a 410 response code is received
322 :raises InvalidContentType: If a 415 response code is received
323 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
324 :raises InvalidHttpSuccessCode: if the read code isn't an expected
325 http success code
326 :raises NotFound: If a 404 response code is received
327 :raises NotImplemented: If a 501 response code is received
328 :raises OverLimit: If a 413 response code is received and over_limit is
329 not in the response body
330 :raises RateLimitExceeded: If a 413 response code is received and
331 over_limit is in the response body
332 :raises ServerFault: If a 500 response code is received
333 :raises Unauthorized: If a 401 response code is received
334 :raises UnexpectedContentType: If the content-type of the response
335 isn't an expect type
336 :raises UnexpectedResponseCode: If a response code above 400 is
337 received and it doesn't fall into any
338 of the handled checks
339 :raises UnprocessableEntity: If a 422 response code is received and
340 couldn't be parsed
341 :returns: A loadbalancer statistics object.
342 """
343 if query_params:
344 request_uri = '{0}/{1}/stats?{2}'.format(self.uri, lb_id,
345 query_params)
346 else:
347 request_uri = '{0}/{1}/stats'.format(self.uri, lb_id)
348
349 response, body = self.get(request_uri)
350 self.expected_success(200, response.status)
351 if return_object_only:
352 return jsonutils.loads(body.decode('utf-8'))['stats']
353 else:
354 return jsonutils.loads(body.decode('utf-8'))
355
356 @skip_if_not_implemented
357 def get_loadbalancer_status(self, lb_id, query_params=None,
358 return_object_only=True):
359 """Get a loadbalancer status tree.
360
361 :param lb_id: The loadbalancer ID to query.
362 :param query_params: The optional query parameters to append to the
363 request. Ex. fields=id&fields=name
364 :param return_object_only: If True, the response returns the object
365 inside the root tag. False returns the full
366 response from the API.
367 :raises AssertionError: if the expected_code isn't a valid http success
368 response code
369 :raises BadRequest: If a 400 response code is received
370 :raises Conflict: If a 409 response code is received
371 :raises Forbidden: If a 403 response code is received
372 :raises Gone: If a 410 response code is received
373 :raises InvalidContentType: If a 415 response code is received
374 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
375 :raises InvalidHttpSuccessCode: if the read code isn't an expected
376 http success code
377 :raises NotFound: If a 404 response code is received
378 :raises NotImplemented: If a 501 response code is received
379 :raises OverLimit: If a 413 response code is received and over_limit is
380 not in the response body
381 :raises RateLimitExceeded: If a 413 response code is received and
382 over_limit is in the response body
383 :raises ServerFault: If a 500 response code is received
384 :raises Unauthorized: If a 401 response code is received
385 :raises UnexpectedContentType: If the content-type of the response
386 isn't an expect type
387 :raises UnexpectedResponseCode: If a response code above 400 is
388 received and it doesn't fall into any
389 of the handled checks
390 :raises UnprocessableEntity: If a 422 response code is received and
391 couldn't be parsed
392 :returns: A loadbalancer statuses object.
393 """
394 if query_params:
395 request_uri = '{0}/{1}/status?{2}'.format(self.uri, lb_id,
396 query_params)
397 else:
398 request_uri = '{0}/{1}/status'.format(self.uri, lb_id)
399
400 response, body = self.get(request_uri)
401 self.expected_success(200, response.status)
402 if return_object_only:
403 return jsonutils.loads(body.decode('utf-8'))['statuses']
404 else:
405 return jsonutils.loads(body.decode('utf-8'))