diff options
-rw-r--r-- | neutronclient/neutron/v2_0/lb/v2/loadbalancer.py | 29 | ||||
-rw-r--r-- | neutronclient/shell.py | 1 | ||||
-rw-r--r-- | neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py | 37 | ||||
-rw-r--r-- | neutronclient/v2_0/client.py | 7 | ||||
-rw-r--r-- | releasenotes/notes/add-lb-status-tree-723f23c09617de3b.yaml | 7 | ||||
-rw-r--r-- | releasenotes/source/old_relnotes.rst | 1 |
6 files changed, 82 insertions, 0 deletions
diff --git a/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py b/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py index 065ac54..caef541 100644 --- a/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py +++ b/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py @@ -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)) diff --git a/neutronclient/shell.py b/neutronclient/shell.py index 508cdce..d7840b8 100644 --- a/neutronclient/shell.py +++ b/neutronclient/shell.py @@ -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, diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py b/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py index cb58c6d..205e681 100644 --- a/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py +++ b/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py @@ -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) diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py index 4dc7382..a58e9b5 100644 --- a/neutronclient/v2_0/client.py +++ b/neutronclient/v2_0/client.py @@ -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" @@ -945,6 +946,12 @@ class Client(ClientBase): 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.""" return self.list('listeners', self.lbaas_listeners_path, diff --git a/releasenotes/notes/add-lb-status-tree-723f23c09617de3b.yaml b/releasenotes/notes/add-lb-status-tree-723f23c09617de3b.yaml new file mode 100644 index 0000000..8f48d28 --- /dev/null +++ b/releasenotes/notes/add-lb-status-tree-723f23c09617de3b.yaml @@ -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.
\ No newline at end of file diff --git a/releasenotes/source/old_relnotes.rst b/releasenotes/source/old_relnotes.rst index 6a571a7..0936e32 100644 --- a/releasenotes/source/old_relnotes.rst +++ b/releasenotes/source/old_relnotes.rst @@ -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 ----- |