From db0afea0683b35a2eb8665d47d03fbc793558397 Mon Sep 17 00:00:00 2001 From: tengqm Date: Wed, 7 Jan 2015 14:38:32 +0800 Subject: [PATCH] Remove list_nodes method from cluster It makes little to no sense to have a separate list_nodes method. All nodes can be listed from the same table and same URI. The only difference is that we will have a cluster_id as filters in this case. --- senlinclient/v1/clusters.py | 8 -------- senlinclient/v1/shell.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/senlinclient/v1/clusters.py b/senlinclient/v1/clusters.py index 45b3e978..11cfa8d3 100644 --- a/senlinclient/v1/clusters.py +++ b/senlinclient/v1/clusters.py @@ -102,14 +102,6 @@ class ClusterManager(base.BaseManager): """Delete a cluster.""" self._delete("/clusters/%s" % cluster_id) - def list_nodes(self, cluster_id): - # kwargs contains nodes to be added - cluster = self.get(cluster_id) - resp, body = self.client.json_request( - 'GET', - '/clusters/%s/nodes' % cluster.identifier) - return body - def add_node(self, cluster_id, node_id): headers = self.client.credentials_headers() cluster = self.get(cluster_id) diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 5a200f7c..dbc9a358 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -250,12 +250,38 @@ def do_cluster_show(sc, args): } utils.print_dict(cluster.to_dict(), formatters=formatters) - +@utils.arg('-s', '--show-deleted', default=False, action="store_true", + help=_('Include soft-deleted nodes if any.')) +@utils.arg('-f', '--filters', metavar='', + help=_('Filter parameters to apply on returned nodes. ' + 'This can be specified multiple times, or once with ' + 'parameters separated by a semicolon.'), + action='append') +@utils.arg('-l', '--limit', metavar='', + help=_('Limit the number of nodes returned.')) +@utils.arg('-m', '--marker', metavar='', + help=_('Only return nodes that appear after the given node ID.')) @utils.arg('id', metavar='', help=_('Name or ID of cluster to nodes from.')) def do_cluster_node_list(sc, args): '''List nodes from cluster.''' - sc.clusters.list_nodes(args.id) + fields = ['id', 'name', 'index', 'status', 'physical_id', 'created_time'] + + kwargs = { + 'cluster_id': args.id, + 'show_deleted': args.show_deleted, + 'filters': utils.format_parameters(args.filters), + 'limit': args.limit, + 'marker': args.marker, + } + + try: + nodes = sc.nodes.list(**kwargs) + except exc.HTTPNotFound: + msg = _('No node matching criteria is found') + raise exc.CommandError(msg) + + utils.print_list(nodes, fields, sortby_index=5) @utils.arg('-n', '--nodes', metavar='',