Add code for load balancer status tree
So far the feature of retrieving a specific Load Balancer's Status Tree is not implemented in the neutronclient code, we need to add feature code and related tests. DocImpact Add loadbalancer-status-tree feature in CLI Change-Id: Ia7804ab6baac674830c6834f67cfd411ebf4d14f
This commit is contained in:
parent
ca78051a80
commit
a97f28f187
neutronclient
releasenotes
@ -14,6 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from neutronclient._i18n import _
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
@ -128,3 +129,31 @@ class RetrieveLoadBalancerStats(neutronV20.ShowCommand):
|
||||
# here covert the data dict to the 1-1 vector format below:
|
||||
# [(field1, field2, field3, ...), (value1, value2, value3, ...)]
|
||||
return list(zip(*sorted(stats.items())))
|
||||
|
||||
|
||||
class RetrieveLoadBalancerStatus(neutronV20.NeutronCommand):
|
||||
"""Retrieve status for a given loadbalancer.
|
||||
|
||||
The only output is a formatted JSON tree, and the table format
|
||||
does not support this type of data.
|
||||
"""
|
||||
resource = 'loadbalancer'
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RetrieveLoadBalancerStatus, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
self.resource, metavar=self.resource.upper(),
|
||||
help=_('ID or name of %s to show.') % self.resource)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug('run(%s)' % parsed_args)
|
||||
neutron_client = self.get_client()
|
||||
lb_id = neutronV20.find_resourceid_by_name_or_id(
|
||||
neutron_client, self.resource, parsed_args.loadbalancer)
|
||||
params = {}
|
||||
data = neutron_client.retrieve_loadbalancer_status(lb_id, **params)
|
||||
res = data['statuses']
|
||||
if 'statuses' in data:
|
||||
print(jsonutils.dumps(res, indent=4))
|
||||
|
@ -204,6 +204,7 @@ COMMAND_V2 = {
|
||||
'lbaas-loadbalancer-update': lbaas_loadbalancer.UpdateLoadBalancer,
|
||||
'lbaas-loadbalancer-delete': lbaas_loadbalancer.DeleteLoadBalancer,
|
||||
'lbaas-loadbalancer-stats': lbaas_loadbalancer.RetrieveLoadBalancerStats,
|
||||
'lbaas-loadbalancer-status': lbaas_loadbalancer.RetrieveLoadBalancerStatus,
|
||||
'lbaas-listener-list': lbaas_listener.ListListener,
|
||||
'lbaas-listener-show': lbaas_listener.ShowListener,
|
||||
'lbaas-listener-create': lbaas_listener.CreateListener,
|
||||
|
@ -166,3 +166,40 @@ class CLITestV20LbLoadBalancerJSON(test_cli20.CLITestV20Base):
|
||||
self.assertIn('1234', _str)
|
||||
self.assertIn('bytes_out', _str)
|
||||
self.assertIn('4321', _str)
|
||||
|
||||
def test_get_loadbalancer_statuses(self):
|
||||
# lbaas-loadbalancer-status test_id.
|
||||
resource = 'loadbalancer'
|
||||
cmd = lb.RetrieveLoadBalancerStatus(test_cli20.MyApp(sys.stdout), None)
|
||||
my_id = self.test_id
|
||||
args = [my_id]
|
||||
|
||||
self.mox.StubOutWithMock(cmd, "get_client")
|
||||
self.mox.StubOutWithMock(self.client.httpclient, "request")
|
||||
cmd.get_client().MultipleTimes().AndReturn(self.client)
|
||||
|
||||
expected_res = {'statuses': {'operating_status': 'ONLINE',
|
||||
'provisioning_status': 'ACTIVE'}}
|
||||
|
||||
resstr = self.client.serialize(expected_res)
|
||||
|
||||
path = getattr(self.client, "lbaas_loadbalancer_path_status")
|
||||
return_tup = (test_cli20.MyResp(200), resstr)
|
||||
self.client.httpclient.request(
|
||||
test_cli20.end_url(path % my_id), 'GET',
|
||||
body=None,
|
||||
headers=mox.ContainsKeyValue(
|
||||
'X-Auth-Token', test_cli20.TOKEN)).AndReturn(return_tup)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
cmd_parser = cmd.get_parser("test_" + resource)
|
||||
parsed_args = cmd_parser.parse_args(args)
|
||||
cmd.run(parsed_args)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
_str = self.fake_stdout.make_string()
|
||||
self.assertIn('operating_status', _str)
|
||||
self.assertIn('ONLINE', _str)
|
||||
self.assertIn('provisioning_status', _str)
|
||||
self.assertIn('ACTIVE', _str)
|
||||
|
@ -342,6 +342,7 @@ class Client(ClientBase):
|
||||
lbaas_loadbalancers_path = "/lbaas/loadbalancers"
|
||||
lbaas_loadbalancer_path = "/lbaas/loadbalancers/%s"
|
||||
lbaas_loadbalancer_path_stats = "/lbaas/loadbalancers/%s/stats"
|
||||
lbaas_loadbalancer_path_status = "/lbaas/loadbalancers/%s/statuses"
|
||||
lbaas_listeners_path = "/lbaas/listeners"
|
||||
lbaas_listener_path = "/lbaas/listeners/%s"
|
||||
lbaas_pools_path = "/lbaas/pools"
|
||||
@ -944,6 +945,12 @@ class Client(ClientBase):
|
||||
return self.get(self.lbaas_loadbalancer_path_stats % (loadbalancer),
|
||||
params=_params)
|
||||
|
||||
@APIParamsCall
|
||||
def retrieve_loadbalancer_status(self, loadbalancer, **_params):
|
||||
"""Retrieves status for a certain load balancer."""
|
||||
return self.get(self.lbaas_loadbalancer_path_status % (loadbalancer),
|
||||
params=_params)
|
||||
|
||||
@APIParamsCall
|
||||
def list_listeners(self, retrieve_all=True, **_params):
|
||||
"""Fetches a list of all lbaas_listeners for a tenant."""
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
CLI support for load balancer status tree.
|
||||
|
||||
* The ``lbaas-loadbalancer-status`` command provides the status
|
||||
tree of a specific load balancer.
|
@ -10,6 +10,7 @@ Old Release Notes
|
||||
* made the publicURL the default endpoint instead of adminURL
|
||||
* add ability to update security group name (requires 2013.2-Havana or later)
|
||||
* add flake8 and pbr support for testing and building
|
||||
* add ability to retrieve a specific load balancer's status tree
|
||||
|
||||
2.2.0
|
||||
-----
|
||||
|
Loading…
x
Reference in New Issue
Block a user