From 8b2c227f27be649a4a3e371ad99157ee464ecc1d Mon Sep 17 00:00:00 2001 From: Sulochan Acharya Date: Mon, 22 Oct 2012 17:01:46 -0500 Subject: [PATCH] Allow deletion of multiple images through CLI Add nargs to argparse for image-delete command to allow muliple (optional) positional image-id arguments. For example: image-delete xxx aaa yyy will delete valid images xxx and yyy and print error message for invalid image aaa. Also with --verbose you can see some extra text on delete request for each image. Fixes bug1056498. Change-Id: I6e804700ed24d16f90ec92569c0893cad4aaa26f --- glanceclient/v1/shell.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py index 8aef310..931846d 100644 --- a/glanceclient/v1/shell.py +++ b/glanceclient/v1/shell.py @@ -23,6 +23,7 @@ if os.name == 'nt': else: msvcrt = None +from glanceclient import exc from glanceclient.common import utils import glanceclient.v1.images @@ -257,10 +258,24 @@ def do_image_update(gc, args): _image_show(image) -@utils.arg('id', metavar='', help='ID of image to delete.') +@utils.arg('id', metavar='', nargs='+', + help='ID of image(s) to delete.') def do_image_delete(gc, args): - """Delete a specific image.""" - gc.images.delete(args.id) + """Delete specified image(s).""" + for image in args.id: + try: + if args.verbose: + print 'Requesting image delete for %s ...' % image, + + gc.images.delete(image) + + if args.verbose: + print '[Done]' + + except exc.HTTPException, e: + if args.verbose: + print '[Fail]' + print '%s: Unable to delete image %s' % (e, image) @utils.arg('--image-id', metavar='',