diff options
author | minwang <swiftwangster@gmail.com> | 2015-11-17 16:53:05 -0800 |
---|---|---|
committer | minwang <swiftwangster@gmail.com> | 2016-01-19 10:01:58 -0800 |
commit | a97f28f18729a55f3cdc0c7c21d6a183d6b01a1c (patch) | |
tree | 4de14688d4837008d1a00513232ce262e343c7e1 /neutronclient/neutron | |
parent | ca78051a8002e90b04a8f945eb2daf068436162c (diff) | |
download | python-neutronclient-a97f28f18729a55f3cdc0c7c21d6a183d6b01a1c.tar.gz |
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
Diffstat (limited to 'neutronclient/neutron')
-rw-r--r-- | neutronclient/neutron/v2_0/lb/v2/loadbalancer.py | 29 |
1 files changed, 29 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)) |