Add listener stats client api and osc
Change-Id: I0e063e99fd56c9e3428027fe35eb734deea4b9df Story: 1686566 Task: 5351
This commit is contained in:
parent
c7100d548f
commit
6ec5b30299
|
@ -21,6 +21,7 @@ BASE_LOADBALANCER_FAILOVER_URL = BASE_SINGLE_LB_URL + '/failover'
|
|||
|
||||
BASE_LISTENER_URL = BASE_LBAAS_ENDPOINT + '/listeners'
|
||||
BASE_SINGLE_LISTENER_URL = BASE_LISTENER_URL + '/{uuid}'
|
||||
BASE_LISTENER_STATS_URL = BASE_SINGLE_LISTENER_URL + '/stats'
|
||||
|
||||
BASE_POOL_URL = BASE_LBAAS_ENDPOINT + '/pools'
|
||||
BASE_SINGLE_POOL_URL = BASE_POOL_URL + '/{pool_id}'
|
||||
|
|
|
@ -221,6 +221,19 @@ class OctaviaAPI(api.BaseAPI):
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -312,3 +312,32 @@ class SetListener(command.Command):
|
|||
|
||||
self.app.client_manager.load_balancer.listener_set(
|
||||
listener_id, json=body)
|
||||
|
||||
|
||||
class ShowListenerStats(command.ShowOne):
|
||||
"""Shows the current statistics for a listener."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowListenerStats, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'listener',
|
||||
metavar='<listener>',
|
||||
help='Name or UUID of the listener'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
rows = const.LOAD_BALANCER_STATS_ROWS
|
||||
attrs = v2_utils.get_listener_attrs(self.app.client_manager,
|
||||
parsed_args)
|
||||
|
||||
listener_id = attrs.pop('listener_id')
|
||||
|
||||
data = self.app.client_manager.load_balancer.listener_stats_show(
|
||||
listener_id=listener_id,
|
||||
)
|
||||
|
||||
return (rows, (utils.get_dict_properties(
|
||||
data['stats'], rows, formatters={})))
|
||||
|
|
|
@ -328,6 +328,16 @@ class TestLoadBalancer(TestOctaviaClient):
|
|||
self.api.listener_delete,
|
||||
FAKE_LI)
|
||||
|
||||
def test_stats_show_listener(self):
|
||||
self.requests_mock.register_uri(
|
||||
'GET',
|
||||
FAKE_LBAAS_URL + 'listeners/' + FAKE_LI + '/stats',
|
||||
json=SINGLE_LB_STATS_RESP,
|
||||
status_code=200,
|
||||
)
|
||||
ret = self.api.listener_stats_show(FAKE_LI)
|
||||
self.assertEqual(SINGLE_LB_STATS_RESP, ret)
|
||||
|
||||
def test_list_pool_no_options(self):
|
||||
self.requests_mock.register_uri(
|
||||
'GET',
|
||||
|
|
|
@ -247,3 +247,26 @@ class TestListenerSet(TestListener):
|
|||
'default_tls_container_ref':
|
||||
self._li.default_tls_container_ref
|
||||
}})
|
||||
|
||||
|
||||
class TestListenerStatsShow(TestListener):
|
||||
|
||||
def setUp(self):
|
||||
super(TestListenerStatsShow, self).setUp()
|
||||
listener_stats_info = {'stats': {'bytes_in': '0'}}
|
||||
self.api_mock.listener_stats_show.return_value = {
|
||||
'stats': listener_stats_info['stats']}
|
||||
lb_client = self.app.client_manager
|
||||
lb_client.load_balancer = self.api_mock
|
||||
self.cmd = listener.ShowListenerStats(self.app, None)
|
||||
|
||||
def test_listener_stats_show(self):
|
||||
arglist = [self._li.id]
|
||||
verifylist = [
|
||||
('listener', self._li.id),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.listener_stats_show.assert_called_with(
|
||||
listener_id=self._li.id)
|
||||
|
|
|
@ -39,6 +39,7 @@ openstack.load_balancer.v2 =
|
|||
loadbalancer_listener_show = octaviaclient.osc.v2.listener:ShowListener
|
||||
loadbalancer_listener_delete = octaviaclient.osc.v2.listener:DeleteListener
|
||||
loadbalancer_listener_set = octaviaclient.osc.v2.listener:SetListener
|
||||
loadbalancer_listener_stats_show = octaviaclient.osc.v2.listener:ShowListenerStats
|
||||
loadbalancer_pool_create = octaviaclient.osc.v2.pool:CreatePool
|
||||
loadbalancer_pool_list = octaviaclient.osc.v2.pool:ListPool
|
||||
loadbalancer_pool_show = octaviaclient.osc.v2.pool:ShowPool
|
||||
|
|
Loading…
Reference in New Issue