From 217f7e8e9a342f37910fcd352d2d5f7cff049987 Mon Sep 17 00:00:00 2001 From: Kevin Zhao Date: Tue, 8 Aug 2017 11:10:37 +0800 Subject: [PATCH] add capsule describe Part of blueprint introduce-compose Change-Id: I5b9ab976b820056706c91b201c9439aaeeca7ea5 Signed-off-by: Kevin Zhao --- zunclient/experimental/capsules.py | 6 ++++++ zunclient/experimental/capsules_shell.py | 25 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/zunclient/experimental/capsules.py b/zunclient/experimental/capsules.py index 405f2f08..bae525ed 100644 --- a/zunclient/experimental/capsules.py +++ b/zunclient/experimental/capsules.py @@ -104,3 +104,9 @@ class CapsuleManager(base.Manager): def delete(self, id, force): return self._delete(self._path(id), qparams={'force': force}) + + def describe(self, id): + try: + return self._list(self._path(id))[0] + except IndexError: + return None diff --git a/zunclient/experimental/capsules_shell.py b/zunclient/experimental/capsules_shell.py index b21cf00d..190d155c 100644 --- a/zunclient/experimental/capsules_shell.py +++ b/zunclient/experimental/capsules_shell.py @@ -12,6 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +import json +import yaml + from zunclient.common import cliutils as utils from zunclient.common import template_utils from zunclient.common import utils as zun_utils @@ -93,3 +96,25 @@ def do_capsule_delete(cs, args): except Exception as e: print("Delete for capsule %(capsule)s failed: %(e)s" % {'capsule': capsule, 'e': e}) + + +@utils.arg('capsule', + metavar='', + help='ID or name of the capsule to show.') +@utils.arg('-f', '--format', + metavar='', + action='store', + choices=['json', 'yaml', 'table'], + default='table', + help='Print representation of the capsule. ' + 'The choices of the output format is json,table,yaml. ' + 'Defaults to table. ') +def do_capsule_describe(cs, args): + """Show details of a capsule.""" + capsule = cs.capsules.describe(args.capsule) + if args.format == 'json': + print(json.dumps(capsule._info, indent=4, sort_keys=True)) + elif args.format == 'yaml': + print(yaml.safe_dump(capsule._info, default_flow_style=False)) + elif args.format == 'table': + _show_capsule(capsule)