Add Octavia (load_balancer) load balancer failover
This patch adds a Octavia (load_balancer) load balancer failover method. It also corrects the resource documentation for the Octavia stats resource classes. Depends-On: https://review.openstack.org/634344 Change-Id: I7384351a5b59b2d68d6a45c543449815adfe52f2
This commit is contained in:
parent
f31930a576
commit
41d6d33339
doc/source/user
openstack
load_balancer/v2
tests
functional/load_balancer/v2
unit/load_balancer
releasenotes/notes
@ -22,6 +22,7 @@ Load Balancer Operations
|
||||
.. automethod:: openstack.load_balancer.v2._proxy.Proxy.get_load_balancer_statistics
|
||||
.. automethod:: openstack.load_balancer.v2._proxy.Proxy.load_balancers
|
||||
.. automethod:: openstack.load_balancer.v2._proxy.Proxy.update_load_balancer
|
||||
.. automethod:: openstack.load_balancer.v2._proxy.Proxy.failover_load_balancer
|
||||
|
||||
Listener Operations
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -10,3 +10,12 @@ The ``Listener`` class inherits from :class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.load_balancer.v2.listener.Listener
|
||||
:members:
|
||||
|
||||
The ListenerStats Class
|
||||
-----------------------
|
||||
|
||||
The ``ListenerStats`` class inherits from
|
||||
:class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.load_balancer.v2.listener.ListenerStats
|
||||
:members:
|
||||
|
@ -10,3 +10,21 @@ The ``LoadBalancer`` class inherits from :class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.load_balancer.v2.load_balancer.LoadBalancer
|
||||
:members:
|
||||
|
||||
The LoadBalancerStats Class
|
||||
---------------------------
|
||||
|
||||
The ``LoadBalancerStats`` class inherits from
|
||||
:class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.load_balancer.v2.load_balancer.LoadBalancerStats
|
||||
:members:
|
||||
|
||||
The LoadBalancerFailover Class
|
||||
------------------------------
|
||||
|
||||
The ``LoadBalancerFailover`` class inherits from
|
||||
:class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.load_balancer.v2.load_balancer.LoadBalancerFailover
|
||||
:members:
|
||||
|
@ -126,6 +126,15 @@ class Proxy(proxy.Proxy):
|
||||
return resource.wait_for_status(self, lb, status, failures, interval,
|
||||
wait, attribute='provisioning_status')
|
||||
|
||||
def failover_load_balancer(self, name_or_id, **attrs):
|
||||
"""Failover a load balancer
|
||||
|
||||
:param name_or_id: The name or ID of a load balancer
|
||||
|
||||
:returns: ``None``
|
||||
"""
|
||||
return self._update(_lb.LoadBalancerFailover, lb_id=name_or_id)
|
||||
|
||||
def create_listener(self, **attrs):
|
||||
"""Create a new listener from attributes
|
||||
|
||||
|
@ -33,7 +33,7 @@ class LoadBalancer(resource.Resource, resource.TagMixin):
|
||||
**resource.TagMixin._tag_query_parameters
|
||||
)
|
||||
|
||||
#: Properties
|
||||
# Properties
|
||||
#: The administrative state of the load balancer *Type: bool*
|
||||
is_admin_state_up = resource.Body('admin_state_up', type=bool)
|
||||
#: Timestamp when the load balancer was created
|
||||
@ -113,3 +113,38 @@ class LoadBalancerStats(resource.Resource):
|
||||
request_errors = resource.Body('request_errors', type=int)
|
||||
#: The total connections handled.
|
||||
total_connections = resource.Body('total_connections', type=int)
|
||||
|
||||
|
||||
class LoadBalancerFailover(resource.Resource):
|
||||
base_path = '/lbaas/loadbalancers/%(lb_id)s/failover'
|
||||
|
||||
# capabilities
|
||||
allow_create = False
|
||||
allow_fetch = False
|
||||
allow_commit = True
|
||||
allow_delete = False
|
||||
allow_list = False
|
||||
|
||||
requires_id = False
|
||||
|
||||
# Properties
|
||||
#: The ID of the load balancer.
|
||||
lb_id = resource.URI('lb_id')
|
||||
|
||||
# The parent commit method assumes there is a header or body change,
|
||||
# which we do not have here. The default _update code path also has no
|
||||
# way to pass has_body into this function, so overriding the method here.
|
||||
def commit(self, session, base_path=None):
|
||||
kwargs = {}
|
||||
request = self._prepare_request(prepend_key=False,
|
||||
base_path=base_path,
|
||||
**kwargs)
|
||||
session = self._get_session(session)
|
||||
kwargs = {}
|
||||
microversion = self._get_microversion_for(session, 'commit')
|
||||
response = session.put(request.url, json=request.body,
|
||||
headers=request.headers,
|
||||
microversion=microversion, **kwargs)
|
||||
self.microversion = microversion
|
||||
self._translate_response(response, has_body=False)
|
||||
return self
|
||||
|
@ -228,6 +228,13 @@ class TestLoadBalancer(base.BaseFunctionalTest):
|
||||
test_lb = self.conn.load_balancer.get_load_balancer(self.LB_ID)
|
||||
self.assertEqual(self.LB_NAME, test_lb.name)
|
||||
|
||||
def test_lb_failover(self):
|
||||
self.conn.load_balancer.failover_load_balancer(self.LB_ID)
|
||||
self.conn.load_balancer.wait_for_load_balancer(
|
||||
self.LB_ID, wait=self._wait_for_timeout)
|
||||
test_lb = self.conn.load_balancer.get_load_balancer(self.LB_ID)
|
||||
self.assertEqual(self.LB_NAME, test_lb.name)
|
||||
|
||||
def test_listener_find(self):
|
||||
test_listener = self.conn.load_balancer.find_listener(
|
||||
self.LISTENER_NAME)
|
||||
|
@ -187,3 +187,16 @@ class TestLoadBalancerStats(base.TestCase):
|
||||
test_load_balancer.request_errors)
|
||||
self.assertEqual(EXAMPLE_STATS['total_connections'],
|
||||
test_load_balancer.total_connections)
|
||||
|
||||
|
||||
class TestLoadBalancerFailover(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
test_load_balancer = load_balancer.LoadBalancerFailover()
|
||||
self.assertEqual('/lbaas/loadbalancers/%(lb_id)s/failover',
|
||||
test_load_balancer.base_path)
|
||||
self.assertFalse(test_load_balancer.allow_create)
|
||||
self.assertFalse(test_load_balancer.allow_fetch)
|
||||
self.assertFalse(test_load_balancer.allow_delete)
|
||||
self.assertFalse(test_load_balancer.allow_list)
|
||||
self.assertTrue(test_load_balancer.allow_commit)
|
||||
|
@ -97,6 +97,13 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
|
||||
self.verify_update(self.proxy.update_load_balancer,
|
||||
lb.LoadBalancer)
|
||||
|
||||
def test_load_balancer_failover(self):
|
||||
self.verify_update(self.proxy.failover_load_balancer,
|
||||
lb.LoadBalancerFailover,
|
||||
value=[self.LB_ID],
|
||||
expected_args=[],
|
||||
expected_kwargs={'lb_id': self.LB_ID})
|
||||
|
||||
def test_listeners(self):
|
||||
self.verify_list(self.proxy.listeners,
|
||||
listener.Listener)
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added Octavia (load_balancer) load balancer failover.
|
Loading…
Reference in New Issue
Block a user