diff options
Diffstat (limited to 'glanceclient/v2/shell.py')
-rw-r--r-- | glanceclient/v2/shell.py | 94 |
1 files changed, 90 insertions, 4 deletions
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 5f83bd2..be627f5 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -23,6 +23,7 @@ from glanceclient._i18n import _ from glanceclient.common import progressbar from glanceclient.common import utils from glanceclient import exc +from glanceclient.v2 import cache from glanceclient.v2 import image_members from glanceclient.v2 import image_schema from glanceclient.v2 import images @@ -486,6 +487,15 @@ def do_image_tasks(gc, args): utils.exit('Server does not support image tasks API (v2.12)') +def do_usage(gc, args): + """Get quota usage information.""" + columns = ['Quota', 'Limit', 'Usage'] + usage = gc.info.get_usage() + utils.print_dict_list( + [dict(v, quota=k) for k, v in usage.items()], + columns) + + @utils.arg('--image-id', metavar='<IMAGE_ID>', required=True, help=_('Image to display members of.')) def do_member_list(gc, args): @@ -574,11 +584,15 @@ def do_import_info(gc, args): else: utils.print_dict(import_info) - +@utils.arg('--detail', default=False, action='store_true', + help='Shows details of stores. Admin only.') def do_stores_info(gc, args): """Print available backends from Glance.""" try: - stores_info = gc.images.get_stores_info() + if args.detail: + stores_info = gc.images.get_stores_info_detail() + else: + stores_info = gc.images.get_stores_info() except exc.HTTPNotFound: utils.exit('Multi Backend support is not enabled') else: @@ -1383,10 +1397,12 @@ def do_md_tag_create(gc, args): @utils.arg('--delim', metavar='<DELIM>', required=False, help=_('The delimiter used to separate the names' ' (if none is provided then the default is a comma).')) +@utils.arg('--append', default=False, action='store_true', required=False, + help=_('Append the new tags to the existing ones instead of' + 'overwriting them')) def do_md_tag_create_multiple(gc, args): """Create new metadata definitions tags inside a namespace.""" delim = args.delim or ',' - tags = [] names_list = args.names.split(delim) for name in names_list: @@ -1398,7 +1414,7 @@ def do_md_tag_create_multiple(gc, args): utils.exit('Please supply at least one tag name. For example: ' '--names Tag1') - fields = {'tags': tags} + fields = {'tags': tags, 'append': args.append} new_tags = gc.metadefs_tag.create_multiple(args.namespace, **fields) columns = ['name'] column_settings = { @@ -1464,6 +1480,76 @@ def do_md_tag_list(gc, args): utils.print_list(tags, columns, field_settings=column_settings) +@utils.arg('--target', default='both', + choices=cache.TARGET_VALUES, + help=_('Specify which target you want to clear')) +def do_cache_clear(gc, args): + """Clear all images from cache, queue or both""" + if not gc.endpoint_provided: + utils.exit("Direct server endpoint needs to be provided. Do not use " + "loadbalanced or catalog endpoints.") + try: + gc.cache.clear(args.target) + except exc.HTTPForbidden: + msg = _("You are not permitted to delete image(s) " + "from cache.") + utils.print_err(msg) + except exc.HTTPException as e: + msg = _("'%s': Unable to delete image(s) from cache." % e) + utils.print_err(msg) + + +@utils.arg('id', metavar='<IMAGE_ID>', nargs='+', + help=_('ID of image(s) to delete from cache/queue.')) +def do_cache_delete(gc, args): + """Delete image from cache/caching queue.""" + if not gc.endpoint_provided: + utils.exit("Direct server endpoint needs to be provided. Do not use " + "loadbalanced or catalog endpoints.") + + for args_id in args.id: + try: + gc.cache.delete(args_id) + except exc.HTTPForbidden: + msg = _("You are not permitted to delete the image '%s' " + "from cache." % args_id) + utils.print_err(msg) + except exc.HTTPException as e: + msg = _("'%s': Unable to delete image '%s' from cache." + % (e, args_id)) + utils.print_err(msg) + + +def do_cache_list(gc, args): + """Get cache state.""" + if not gc.endpoint_provided: + utils.exit("Direct server endpoint needs to be provided. Do not use " + "loadbalanced or catalog endpoints.") + cached_images = gc.cache.list() + utils.print_cached_images(cached_images) + + +@utils.arg('id', metavar='<IMAGE_ID>', nargs='+', + help=_('ID of image(s) to queue for caching.')) +def do_cache_queue(gc, args): + """Queue image(s) for caching.""" + if not gc.endpoint_provided: + utils.exit("Direct server endpoint needs to be provided. Do not use " + "loadbalanced or catalog endpoints.") + + for args_id in args.id: + try: + gc.cache.queue(args_id) + except exc.HTTPForbidden: + msg = _("You are not permitted to queue the image '%s' " + "for caching." % args_id) + utils.print_err(msg) + except exc.HTTPException as e: + msg = _("'%s': Unable to queue image '%s' for caching." + % (e, args_id)) + utils.print_err(msg) + + @utils.arg('--sort-key', default='status', choices=tasks.SORT_KEY_VALUES, help=_('Sort task list by specified field.')) |