/usr/lib/python2.7/dist-packages/octaviaclient/api/v2/octavia.py is in python-octaviaclient 1.4.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""Octavia API Library"""
from osc_lib.api import api
from octaviaclient.api import constants as const
def correct_return_codes(func):
_status_dict = {400: 'Bad Request', 401: 'Unauthorized',
403: 'Forbidden', 404: 'Not found',
409: 'Conflict', 413: 'Over Limit',
501: 'Not Implemented'}
def wrapper(*args, **kwargs):
try:
response = func(*args, **kwargs)
except Exception as e:
if not hasattr(e, 'response'):
raise
raise OctaviaClientException(
code=e.response.status_code,
message=e.response.json().get(
'faultstring',
_status_dict.get(e.response.status_code, 'Unknown Error')),
request_id=e.request_id)
return response
return wrapper
class OctaviaAPI(api.BaseAPI):
"""Octavia API"""
_endpoint_suffix = '/v2.0'
def __init__(self, endpoint=None, **kwargs):
super(OctaviaAPI, self).__init__(endpoint=endpoint, **kwargs)
self.endpoint = self.endpoint.rstrip('/')
self._build_url()
def _build_url(self):
if not self.endpoint.endswith(self._endpoint_suffix):
self.endpoint += self._endpoint_suffix
def load_balancer_list(self, **params):
"""List all load balancers
:param params:
Parameters to filter on
:return:
List of load balancers
"""
url = const.BASE_LOADBALANCER_URL
response = self.list(url, **params)
return response
def load_balancer_show(self, lb_id):
"""Show a load balancer
:param string lb_id:
ID of the load balancer to show
:return:
A dict of the specified load balancer's settings
"""
response = self.find(path=const.BASE_LOADBALANCER_URL, value=lb_id)
return response
@correct_return_codes
def load_balancer_create(self, **params):
"""Create a load balancer
:param params:
Paramaters to create the load balancer with (expects json=)
:return:
A dict of the created load balancer's settings
"""
url = const.BASE_LOADBALANCER_URL
response = self.create(url, **params)
return response
@correct_return_codes
def load_balancer_delete(self, lb_id, **params):
"""Delete a load balancer
:param string lb_id:
The ID of the load balancer to delete
:param params:
A dict of url parameters
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_LB_URL.format(uuid=lb_id)
response = self.delete(url, params=params)
return response
@correct_return_codes
def load_balancer_set(self, lb_id, **params):
"""Update a load balancer's settings
:param string lb_id:
The ID of the load balancer to update
:param params:
A dict of arguments to update a loadbalancer
:return:
Response Code from API
"""
url = const.BASE_SINGLE_LB_URL.format(uuid=lb_id)
response = self.create(url, method='PUT', **params)
return response
def load_balancer_stats_show(self, lb_id, **kwargs):
"""Shows the current statistics for a load balancer.
:param string lb_id:
ID of the load balancer
:return:
A dict of the specified load balancer's statistics
"""
url = const.BASE_LB_STATS_URL.format(uuid=lb_id)
response = self.list(url, **kwargs)
return response
@correct_return_codes
def load_balancer_failover(self, lb_id):
"""Trigger load balancer failover
:param string lb_id:
ID of the load balancer to failover
:return:
Response Code from the API
"""
url = const.BASE_LOADBALANCER_FAILOVER_URL.format(uuid=lb_id)
response = self.create(url, method='PUT')
return response
def listener_list(self, **kwargs):
"""List all listeners
:param kwargs:
Parameters to filter on
:return:
List of listeners
"""
url = const.BASE_LISTENER_URL
response = self.list(url, **kwargs)
return response
def listener_show(self, listener_id):
"""Show a listener
:param string listener_id:
ID of the listener to show
:return:
A dict of the specified listener's settings
"""
response = self.find(path=const.BASE_LISTENER_URL, value=listener_id)
return response
@correct_return_codes
def listener_create(self, **kwargs):
"""Create a listener
:param kwargs:
Parameters to create a listener with (expects json=)
:return:
A dict of the created listener's settings
"""
url = const.BASE_LISTENER_URL
response = self.create(url, **kwargs)
return response
@correct_return_codes
def listener_delete(self, listener_id):
"""Delete a listener
:param stirng listener_id:
ID of of listener to delete
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_LISTENER_URL.format(uuid=listener_id)
response = self.delete(url)
return response
@correct_return_codes
def listener_set(self, listener_id, **kwargs):
"""Update a listener's settings
:param string listener_id:
ID of the listener to update
:param kwargs:
A dict of arguments to update a listener
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_LISTENER_URL.format(uuid=listener_id)
response = self.create(url, method='PUT', **kwargs)
return response
def listener_stats_show(self, listener_id, **kwargs):
"""Shows the current statistics for a listener
:param string listener_id:
ID of the listener
:return:
A dict of the specified listener's statistics
"""
url = const.BASE_LISTENER_STATS_URL.format(uuid=listener_id)
response = self.list(url, **kwargs)
return response
def pool_list(self, **kwargs):
"""List all pools
:param kwargs:
Parameters to filter on
:return:
List of pools
"""
url = const.BASE_POOL_URL
response = self.list(url, **kwargs)
return response
@correct_return_codes
def pool_create(self, **kwargs):
"""Create a pool
:param kwargs:
Parameters to create a listener with (expects json=)
:return:
A dict of the created pool's settings
"""
url = const.BASE_POOL_URL
response = self.create(url, **kwargs)
return response
@correct_return_codes
def pool_delete(self, pool_id):
"""Delete a pool
:param string pool_id:
ID of of pool to delete
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_POOL_URL.format(pool_id=pool_id)
response = self.delete(url)
return response
def pool_show(self, pool_id):
"""Show a pool's settings
:param string pool_id:
ID of the pool to show
:return:
Dict of the specified pool's settings
"""
response = self.find(path=const.BASE_POOL_URL, value=pool_id)
return response
@correct_return_codes
def pool_set(self, pool_id, **kwargs):
"""Update a pool's settings
:param pool_id:
ID of the pool to update
:param kwargs:
A dict of arguments to update a pool
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_POOL_URL.format(pool_id=pool_id)
response = self.create(url, method='PUT', **kwargs)
return response
def member_list(self, pool_id, **kwargs):
"""Lists the member from a given pool id
:param pool_id:
ID of the pool
:param kwargs:
A dict of filter arguments
:return:
Response list members
"""
url = const.BASE_MEMBER_URL.format(pool_id=pool_id)
response = self.list(url, **kwargs)
return response
def member_show(self, pool_id, member_id):
"""Showing a member details of a pool
:param pool_id:
ID of pool the member is added
:param member_id:
ID of the member
:param kwargs:
A dict of arguments
:return:
Response of member
"""
url = const.BASE_MEMBER_URL.format(pool_id=pool_id)
response = self.find(path=url, value=member_id)
return response
@correct_return_codes
def member_create(self, pool_id, **kwargs):
"""Creating a member for the given pool id
:param pool_id:
ID of pool to which member is added
:param kwargs:
A Dict of arguments
:return:
A member details on successful creation
"""
url = const.BASE_MEMBER_URL.format(pool_id=pool_id)
response = self.create(url, **kwargs)
return response
@correct_return_codes
def member_delete(self, pool_id, member_id):
"""Removing a member from a pool and mark that member as deleted
:param pool_id:
ID of the pool
:param member_id:
ID of the member to be deleted
:return:
Response code from the API
"""
url = const.BASE_SINGLE_MEMBER_URL.format(pool_id=pool_id,
member_id=member_id)
response = self.delete(url)
return response
@correct_return_codes
def member_set(self, pool_id, member_id, **kwargs):
"""Updating a member settings
:param pool_id:
ID of the pool
:param member_id:
ID of the member to be updated
:param kwargs:
A dict of the values of member to be updated
:return:
Response code from the API
"""
url = const.BASE_SINGLE_MEMBER_URL.format(pool_id=pool_id,
member_id=member_id)
response = self.create(url, method='PUT', **kwargs)
return response
def l7policy_list(self, **kwargs):
"""List all l7policies
:param kwargs:
Parameters to filter on
:return:
List of l7policies
"""
url = const.BASE_L7POLICY_URL
response = self.list(url, **kwargs)
return response
@correct_return_codes
def l7policy_create(self, **kwargs):
"""Create a l7policy
:param kwargs:
Parameters to create a l7policy with (expects json=)
:return:
A dict of the created l7policy's settings
"""
url = const.BASE_L7POLICY_URL
response = self.create(url, **kwargs)
return response
@correct_return_codes
def l7policy_delete(self, l7policy_id):
"""Delete a l7policy
:param string l7policy_id:
ID of of l7policy to delete
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_L7POLICY_URL.format(policy_uuid=l7policy_id)
response = self.delete(url)
return response
def l7policy_show(self, l7policy_id):
"""Show a l7policy's settings
:param string l7policy_id:
ID of the l7policy to show
:return:
Dict of the specified l7policy's settings
"""
response = self.find(path=const.BASE_L7POLICY_URL, value=l7policy_id)
return response
@correct_return_codes
def l7policy_set(self, l7policy_id, **kwargs):
"""Update a l7policy's settings
:param l7policy_id:
ID of the l7policy to update
:param kwargs:
A dict of arguments to update a l7policy
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_L7POLICY_URL.format(policy_uuid=l7policy_id)
response = self.create(url, method='PUT', **kwargs)
return response
def l7rule_list(self, l7policy_id, **kwargs):
"""List all l7rules for a l7policy
:param kwargs:
Parameters to filter on
:return:
List of l7policies
"""
url = const.BASE_L7RULE_URL.format(policy_uuid=l7policy_id)
response = self.list(url, **kwargs)
return response
@correct_return_codes
def l7rule_create(self, l7policy_id, **kwargs):
"""Create a l7rule
:param string l7policy_id:
The l7policy to create the l7rule for
:param kwargs:
Parameters to create a l7rule with (expects json=)
:return:
A dict of the created l7rule's settings
"""
url = const.BASE_L7RULE_URL.format(policy_uuid=l7policy_id)
response = self.create(url, **kwargs)
return response
@correct_return_codes
def l7rule_delete(self, l7rule_id, l7policy_id):
"""Delete a l7rule
:param string l7rule_id:
ID of of listener to delete
:param string l7policy_id:
ID of the l7policy for this l7rule
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_L7RULE_URL.format(rule_uuid=l7rule_id,
policy_uuid=l7policy_id)
response = self.delete(url)
return response
def l7rule_show(self, l7rule_id, l7policy_id):
"""Show a l7rule's settings
:param string l7rule_id:
ID of the l7rule to show
:param string l7policy_id:
ID of the l7policy for this l7rule
:return:
Dict of the specified l7rule's settings
"""
url = const.BASE_L7RULE_URL.format(policy_uuid=l7policy_id)
response = self.find(path=url, value=l7rule_id)
return response
@correct_return_codes
def l7rule_set(self, l7rule_id, l7policy_id, **kwargs):
"""Update a l7rule's settings
:param l7rule_id:
ID of the l7rule to update
:param string l7policy_id:
ID of the l7policy for this l7rule
:param kwargs:
A dict of arguments to update a l7rule
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_L7RULE_URL.format(rule_uuid=l7rule_id,
policy_uuid=l7policy_id)
response = self.create(url, method='PUT', **kwargs)
return response
def health_monitor_list(self, **kwargs):
"""List all health monitors
:param kwargs:
Parameters to filter on
:return:
A dict containing a list of health monitors
"""
url = const.BASE_HEALTH_MONITOR_URL
response = self.list(url, **kwargs)
return response
@correct_return_codes
def health_monitor_create(self, **kwargs):
"""Create a health monitor
:param kwargs:
Parameters to create a health monitor with (expects json=)
:return:
A dict of the created health monitor's settings
"""
url = const.BASE_HEALTH_MONITOR_URL
response = self.create(url, **kwargs)
return response
@correct_return_codes
def health_monitor_delete(self, health_monitor_id):
"""Delete a health_monitor
:param string health_monitor_id:
ID of of health monitor to delete
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_HEALTH_MONITOR_URL.format(
uuid=health_monitor_id)
response = self.delete(url)
return response
def health_monitor_show(self, health_monitor_id):
"""Show a health monitor's settings
:param string health_monitor_id:
ID of the health monitor to show
:return:
Dict of the specified health monitor's settings
"""
url = const.BASE_HEALTH_MONITOR_URL
response = self.find(path=url, value=health_monitor_id)
return response
@correct_return_codes
def health_monitor_set(self, health_monitor_id, **kwargs):
"""Update a health monitor's settings
:param health_monitor_id:
ID of the health monitor to update
:param kwargs:
A dict of arguments to update a l7policy
:return:
Response Code from the API
"""
url = const.BASE_SINGLE_HEALTH_MONITOR_URL.format(
uuid=health_monitor_id)
response = self.create(url, method='PUT', **kwargs)
return response
def quota_list(self, **params):
"""List all quotas
:param params:
Parameters to filter on (not implemented)
:return:
A ``dict`` representing a list of quotas for the project
"""
url = const.BASE_QUOTA_URL
response = self.list(url, **params)
return response
def quota_show(self, project_id):
"""Show a quota
:param string project_id:
ID of the project to show
:return:
A ``dict`` representing the quota for the project
"""
response = self.find(path=const.BASE_QUOTA_URL, value=project_id)
return response
@correct_return_codes
def quota_reset(self, project_id):
"""Reset a quota
:param string project_id:
The ID of the project to reset quotas
:return:
``None``
"""
url = const.BASE_SINGLE_QUOTA_URL.format(uuid=project_id)
response = self.delete(url)
return response
@correct_return_codes
def quota_set(self, project_id, **params):
"""Update a quota's settings
:param string project_id:
The ID of the project to update
:param params:
A ``dict`` of arguments to update project quota
:return:
A ``dict`` representing the updated quota
"""
url = const.BASE_SINGLE_QUOTA_URL.format(uuid=project_id)
response = self.create(url, method='PUT', **params)
return response
def quota_defaults_show(self):
"""Show quota defaults
:return:
A ``dict`` representing a list of quota defaults
"""
url = const.BASE_QUOTA_DEFAULT_URL
response = self.list(url)
return response
def amphora_show(self, amphora_id):
"""Show an amphora
:param string amphora_id:
ID of the amphora to show
:return:
A ``dict`` of the specified amphora's attributes
"""
url = const.BASE_AMPHORA_URL
response = self.find(path=url, value=amphora_id)
return response
def amphora_list(self, **kwargs):
"""List all amphorae
:param kwargs:
Parameters to filter on
:return:
A ``dict`` containing a list of amphorae
"""
url = const.BASE_AMPHORA_URL
response = self.list(path=url, **kwargs)
return response
class OctaviaClientException(Exception):
"""The base exception class for all exceptions this library raises."""
def __init__(self, code, message=None, request_id=None):
self.code = code
self.message = message or self.__class__.message
self.request_id = request_id
def __str__(self):
return "%s (HTTP %s) (Request-ID: %s)" % (self.message,
self.code,
self.request_id)
|