summaryrefslogtreecommitdiff
path: root/heatclient/osc
diff options
context:
space:
mode:
authorAmey Bhide <abhide@vmware.com>2015-11-09 14:59:21 -0800
committerBryan Jones <jonesbr@us.ibm.com>2016-02-12 15:23:12 +0000
commit1d302a93bbad93127665d078dffcc049f03d7996 (patch)
treef3e157684090dfb6d6507ecb64a6c71b0d7ee386 /heatclient/osc
parentefec30e2904a9b5a5f2bbdedd2972e21601cb87a (diff)
downloadpython-heatclient-1d302a93bbad93127665d078dffcc049f03d7996.tar.gz
OSC plugin for stack resource show and list
This change implements the 'openstack stack resource show' and 'openstack stack resource list' commands. Blueprint: heat-support-python-openstackclient Change-Id: I3f9d64e4d76616e201374522f06a4e8938f00d4d
Diffstat (limited to 'heatclient/osc')
-rw-r--r--heatclient/osc/v1/resources.py107
-rw-r--r--heatclient/osc/v1/stack.py2
2 files changed, 108 insertions, 1 deletions
diff --git a/heatclient/osc/v1/resources.py b/heatclient/osc/v1/resources.py
index 9f9a4d0..685629c 100644
--- a/heatclient/osc/v1/resources.py
+++ b/heatclient/osc/v1/resources.py
@@ -16,13 +16,120 @@
import logging
import six
+from cliff import lister
+from cliff import show
from openstackclient.common import exceptions as exc
+from openstackclient.common import utils
from openstackclient.i18n import _
from heatclient.common import format_utils
from heatclient import exc as heat_exc
+class ResourceShow(show.ShowOne):
+ """Display stack resource."""
+
+ log = logging.getLogger(__name__ + '.ResourceShowStack')
+
+ def get_parser(self, prog_name):
+ parser = super(ResourceShow, self).get_parser(prog_name)
+ parser.add_argument(
+ 'stack',
+ metavar='<stack>',
+ help=_('Name or ID of stack to query')
+ )
+ parser.add_argument(
+ 'resource',
+ metavar='<resource>',
+ help=_('Name or ID of resource')
+ )
+ parser.add_argument(
+ '--with-attr',
+ metavar='<attribute>',
+ action='append',
+ help=_('Attribute to show, can be specified multiple times')
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ self.log.debug('take_action(%s)', parsed_args)
+
+ client = self.app.client_manager.orchestration
+
+ try:
+ resource = client.resources.get(parsed_args.stack,
+ parsed_args.resource,
+ with_attr=parsed_args.with_attr)
+ except heat_exc.HTTPNotFound:
+ msg = (_('Stack or resource not found: %(stack)s %(resource)s') %
+ {'stack': parsed_args.stack,
+ 'resource': parsed_args.resource})
+ raise exc.CommandError(msg)
+
+ return self.dict2columns(resource.to_dict())
+
+
+class ResourceList(lister.Lister):
+ """List stack resources."""
+
+ log = logging.getLogger(__name__ + '.ResourceListStack')
+
+ def get_parser(self, prog_name):
+ parser = super(ResourceList, self).get_parser(prog_name)
+ parser.add_argument(
+ 'stack',
+ metavar='<stack>',
+ help=_('Name or ID of stack to query')
+ )
+ parser.add_argument(
+ '--long',
+ action='store_true',
+ help=_('Enable detailed information presented for each resource '
+ 'in resource list')
+ )
+ parser.add_argument(
+ '-n', '--nested-depth',
+ metavar='<DEPTH>',
+ type=int,
+ help=_('Depth of nested stacks from which to display resources')
+ )
+ # TODO(jonesbr):
+ # Add --filter once https://review.openstack.org/#/c/257864/ is merged
+ return parser
+
+ def take_action(self, parsed_args):
+ self.log.debug('take_action(%s)', parsed_args)
+
+ client = self.app.client_manager.orchestration
+
+ fields = {
+ 'nested_depth': parsed_args.nested_depth,
+ 'with_detail': parsed_args.long,
+ }
+
+ try:
+ resources = client.resources.list(parsed_args.stack, **fields)
+ except heat_exc.HTTPNotFound:
+ msg = _('Stack not found: %s') % parsed_args.stack
+ raise exc.CommandError(msg)
+
+ columns = ['physical_resource_id', 'resource_type', 'resource_status',
+ 'updated_time']
+
+ if len(resources) >= 1 and not hasattr(resources[0], 'resource_name'):
+ columns.insert(0, 'logical_resource_id')
+ else:
+ columns.insert(0, 'resource_name')
+
+ if parsed_args.nested_depth or parsed_args.long:
+ columns.append('stack_name')
+
+ return (
+ columns,
+ (utils.get_item_properties(r, columns) for r in resources)
+ )
+
+
class ResourceMetadata(format_utils.JsonFormat):
"""Show resource metadata"""
diff --git a/heatclient/osc/v1/stack.py b/heatclient/osc/v1/stack.py
index d0370a5..98f417e 100644
--- a/heatclient/osc/v1/stack.py
+++ b/heatclient/osc/v1/stack.py
@@ -365,7 +365,7 @@ class UpdateStack(show.ShowOne):
class ShowStack(show.ShowOne):
- """Show stack details"""
+ """Show stack details."""
log = logging.getLogger(__name__ + ".ShowStack")