From fe271369faf7dee129d007bcebe7733933a5d4ca Mon Sep 17 00:00:00 2001 From: tengqm Date: Fri, 23 Jan 2015 16:58:41 +0800 Subject: [PATCH] Added node show support --- senlinclient/v1/models.py | 18 ++++++++++++++++++ senlinclient/v1/shell.py | 38 +++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/senlinclient/v1/models.py b/senlinclient/v1/models.py index b227b1db..6648495b 100644 --- a/senlinclient/v1/models.py +++ b/senlinclient/v1/models.py @@ -272,6 +272,24 @@ class Node(resource.Resource): tags = resource.prop('tags', type=dict) data = resource.prop('data', type=dict) + def to_dict(self): + return { + 'id': self.id, + 'name': self.name, + 'physical_id': self.physical_id, + 'cluster_id': self.cluster_id, + 'profile_id': self.profile_id, + 'index': self.index, + 'role': self.role, + 'created_time': self.created_time, + 'updated_time': self.updated_time, + 'deleted_time': self.deleted_time, + 'status': self.status, + 'status_reason': self.status_reason, + 'tags': self.tags, + 'data': self.data, + } + class Action(resource.Resource): resources_key = 'actions' diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 15526e68..a4642989 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -571,6 +571,25 @@ def do_node_create(sc, args): 'node %s') % (resp['action_id'], resp['id'])) +@utils.arg('id', metavar='', + help=_('Name or ID of the node to show the details for.')) +def do_node_show(sc, args): + '''Show detailed info about the specified node.''' + try: + query = {'id': args.id} + node = sc.get(models.Node, query) + except exc.HTTPNotFound: + msg = _('Node %(id)s is not found') % args.id + raise exc.CommandError(msg) + + formatters = { + 'tags': utils.json_formatter, + 'data': utils.json_formatter, + } + + utils.print_dict(node.to_dict(), formatters=formatters) + + @utils.arg('id', metavar='', nargs='+', help=_('Name or ID of node(s) to delete.')) def do_node_delete(sc, args): @@ -645,25 +664,6 @@ def do_node_join(sc, args): do_node_list(sc) -@utils.arg('id', metavar='', - help=_('Name or ID of the node to show the details for.')) -def do_node_show(sc, args): - '''Show detailed info about the specified node.''' - try: - query = {'id': args.id} - node = sc.get(models.Node, query) - except exc.HTTPNotFound: - msg = _('Node %(id)s is not found') % args.id - raise exc.CommandError(msg) - - formatters = { - 'links': utils.link_formatter, - 'required_by': utils.newline_list_formatter - } - - utils.print_dict(node.to_dict(), formatters=formatters) - - ##### EVENTS