Skip to content

Commit

Permalink
Allow deletion of multiple images through CLI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sulochan committed Oct 24, 2012
1 parent 9004ee4 commit 8b2c227
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions glanceclient/v1/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
else:
msvcrt = None

from glanceclient import exc
from glanceclient.common import utils
import glanceclient.v1.images

Expand Down Expand Up @@ -257,10 +258,24 @@ def do_image_update(gc, args):
_image_show(image)


@utils.arg('id', metavar='<IMAGE_ID>', help='ID of image to delete.')
@utils.arg('id', metavar='<IMAGE_ID>', 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='<IMAGE_ID>',
Expand Down

0 comments on commit 8b2c227

Please sign in to comment.