Add loadbalancer status show client api and osc
Story: 1685388 Task: 5350 Change-Id: Idf375263aa234199cf1ab61d5e27e24c0cb33a7c
This commit is contained in:
parent
199fb06abd
commit
0ab3e56a23
|
@ -26,6 +26,9 @@ loadbalancer
|
|||
.. autoprogram-cliff:: openstack.load_balancer.v2
|
||||
:command: loadbalancer stats show
|
||||
|
||||
.. autoprogram-cliff:: openstack.load_balancer.v2
|
||||
:command: loadbalancer status show
|
||||
|
||||
.. autoprogram-cliff:: openstack.load_balancer.v2
|
||||
:command: loadbalancer failover
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ BASE_OCTAVIA_ENDPOINT = '/octavia'
|
|||
BASE_LOADBALANCER_URL = BASE_LBAAS_ENDPOINT + '/loadbalancers'
|
||||
BASE_SINGLE_LB_URL = BASE_LOADBALANCER_URL + '/{uuid}'
|
||||
BASE_LB_STATS_URL = BASE_SINGLE_LB_URL + '/stats'
|
||||
BASE_LOADBALANCER_STATUS_URL = BASE_SINGLE_LB_URL + '/status'
|
||||
BASE_LOADBALANCER_FAILOVER_URL = BASE_SINGLE_LB_URL + '/failover'
|
||||
|
||||
BASE_LISTENER_URL = BASE_LBAAS_ENDPOINT + '/listeners'
|
||||
|
|
|
@ -138,6 +138,19 @@ class OctaviaAPI(api.BaseAPI):
|
|||
|
||||
return response
|
||||
|
||||
def load_balancer_status_show(self, lb_id, **kwargs):
|
||||
"""Display load balancer status tree in json format.
|
||||
|
||||
:param string lb_id:
|
||||
ID of the load balancer
|
||||
:return:
|
||||
A dict of the specified load balancer's status
|
||||
"""
|
||||
url = const.BASE_LOADBALANCER_STATUS_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
|
||||
|
|
|
@ -17,6 +17,7 @@ from cliff import lister
|
|||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from octaviaclient.osc.v2 import constants as const
|
||||
from octaviaclient.osc.v2 import utils as v2_utils
|
||||
|
@ -335,3 +336,29 @@ class ShowLoadBalancerStats(command.ShowOne):
|
|||
|
||||
return (rows, (utils.get_dict_properties(
|
||||
data['stats'], rows, formatters={})))
|
||||
|
||||
|
||||
class ShowLoadBalancerStatus(command.Command):
|
||||
"""Display load balancer status tree in json format"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowLoadBalancerStatus, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'loadbalancer',
|
||||
metavar='<load_balancer>',
|
||||
help="Name or UUID of the load balancer."
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
attrs = v2_utils.get_loadbalancer_attrs(self.app.client_manager,
|
||||
parsed_args)
|
||||
lb_id = attrs.pop('loadbalancer_id')
|
||||
|
||||
data = self.app.client_manager.load_balancer.load_balancer_status_show(
|
||||
lb_id=lb_id
|
||||
)
|
||||
res = data.get('statuses', {})
|
||||
print(jsonutils.dumps(res, indent=4))
|
||||
|
|
|
@ -90,6 +90,8 @@ LIST_QT_RESP = {
|
|||
SINGLE_LB_RESP = {'loadbalancer': {'id': FAKE_LB, 'name': 'lb1'}}
|
||||
SINGLE_LB_UPDATE = {"loadbalancer": {"admin_state_up": False}}
|
||||
SINGLE_LB_STATS_RESP = {'bytes_in': '0'}
|
||||
SINGLE_LB_STATUS_RESP = {'statuses': {'operating_status': 'ONLINE',
|
||||
'provisioning_status': 'ACTIVE'}}
|
||||
|
||||
SINGLE_LI_RESP = {'listener': {'id': FAKE_LI, 'name': 'li1'}}
|
||||
SINGLE_LI_UPDATE = {"listener": {"admin_state_up": False}}
|
||||
|
@ -243,6 +245,16 @@ class TestLoadBalancer(TestOctaviaClient):
|
|||
ret = self.api.load_balancer_stats_show(FAKE_LB)
|
||||
self.assertEqual(SINGLE_LB_STATS_RESP, ret)
|
||||
|
||||
def test_status_show_load_balancer(self):
|
||||
self.requests_mock.register_uri(
|
||||
'GET',
|
||||
FAKE_LBAAS_URL + 'loadbalancers/' + FAKE_LB + '/status',
|
||||
json=SINGLE_LB_STATUS_RESP,
|
||||
status_code=200,
|
||||
)
|
||||
ret = self.api.load_balancer_status_show(FAKE_LB)
|
||||
self.assertEqual(SINGLE_LB_STATUS_RESP, ret)
|
||||
|
||||
def test_list_listeners_no_options(self):
|
||||
self.requests_mock.register_uri(
|
||||
'GET',
|
||||
|
|
|
@ -284,6 +284,31 @@ class TestLoadBalancerStats(TestLoadBalancer):
|
|||
lb_id=self._lb.id)
|
||||
|
||||
|
||||
class TestLoadBalancerStatus(TestLoadBalancer):
|
||||
def setUp(self):
|
||||
super(TestLoadBalancerStatus, self).setUp()
|
||||
expected_res = {'statuses': {'operating_status': 'ONLINE',
|
||||
'provisioning_status': 'ACTIVE'}}
|
||||
self.api_mock.load_balancer_status_show.return_value = {
|
||||
'statuses': expected_res['statuses']
|
||||
}
|
||||
lb_client = self.app.client_manager
|
||||
lb_client.load_balancer = self.api_mock
|
||||
self.cmd = load_balancer.ShowLoadBalancerStatus(self.app, None)
|
||||
|
||||
def test_load_balancer_status_show(self):
|
||||
# lbaas-loadbalancer-status test_id.
|
||||
arglist = [self._lb.id]
|
||||
verifylist = [
|
||||
('loadbalancer', self._lb.id),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.load_balancer_status_show.assert_called_with(
|
||||
lb_id=self._lb.id)
|
||||
|
||||
|
||||
class TestLoadBalancerFailover(TestLoadBalancer):
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Adds the "openstack loadbalancer status show" command to display the
|
||||
load balancer status tree in JSON format.
|
|
@ -19,6 +19,7 @@ python-openstackclient>=3.12.0 # Apache-2.0
|
|||
os-client-config>=1.28.0 # Apache-2.0
|
||||
osc-lib>=1.8.0 # Apache-2.0
|
||||
oslo.i18n>=3.15.3 # Apache-2.0
|
||||
oslo.serialization!=2.19.1 # Apache-2.0
|
||||
oslo.utils>=3.33.0 # Apache-2.0
|
||||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
PrettyTable<0.8,>=0.7.1 # BSD
|
||||
|
|
|
@ -33,6 +33,7 @@ openstack.load_balancer.v2 =
|
|||
loadbalancer_delete = octaviaclient.osc.v2.load_balancer:DeleteLoadBalancer
|
||||
loadbalancer_set = octaviaclient.osc.v2.load_balancer:SetLoadBalancer
|
||||
loadbalancer_stats_show = octaviaclient.osc.v2.load_balancer:ShowLoadBalancerStats
|
||||
loadbalancer_status_show = octaviaclient.osc.v2.load_balancer:ShowLoadBalancerStatus
|
||||
loadbalancer_failover = octaviaclient.osc.v2.load_balancer:FailoverLoadBalancer
|
||||
loadbalancer_listener_create = octaviaclient.osc.v2.listener:CreateListener
|
||||
loadbalancer_listener_list = octaviaclient.osc.v2.listener:ListListener
|
||||
|
|
Loading…
Reference in New Issue