Browse Source

Add listener stats client api and osc

Change-Id: I0e063e99fd56c9e3428027fe35eb734deea4b9df
Story: 1686566
Task: 5351
changes/10/526610/3
huangshan 4 years ago
parent
commit
6ec5b30299
  1. 1
      octaviaclient/api/constants.py
  2. 13
      octaviaclient/api/v2/octavia.py
  3. 29
      octaviaclient/osc/v2/listener.py
  4. 10
      octaviaclient/tests/unit/api/test_octavia.py
  5. 23
      octaviaclient/tests/unit/osc/v2/test_listener.py
  6. 1
      setup.cfg

1
octaviaclient/api/constants.py

@ -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}'

13
octaviaclient/api/v2/octavia.py

@ -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

29
octaviaclient/osc/v2/listener.py

@ -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={})))

10
octaviaclient/tests/unit/api/test_octavia.py

@ -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',

23
octaviaclient/tests/unit/osc/v2/test_listener.py

@ -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)

1
setup.cfg

@ -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…
Cancel
Save