summaryrefslogtreecommitdiff
path: root/glanceclient/v2/shell.py
diff options
context:
space:
mode:
authorErno Kuvaja <jokke@hp.com>2014-10-14 16:23:45 +0000
committerErno Kuvaja <jokke@hp.com>2014-11-26 09:34:48 +0000
commit8e02b2a64145719dd2bcd870983be53dc4330e30 (patch)
treee06cd030fad155485b579ab57451fe2102fa5b0c /glanceclient/v2/shell.py
parent3b6754a8cc8932cd9645d54acc8d02826993a546 (diff)
downloadpython-glanceclient-8e02b2a64145719dd2bcd870983be53dc4330e30.tar.gz
Allow --file in image-create with v2 Image API
Allows passing --file and --progress to glance image-create with Image API v2. if --file is present the image-create effectively calls image-upload with the newly created image's id and the '--file' + '--progress' paramaters. The image metadata will be printed after the upload call instead of after creation. In a case argumented file does not exist the image will not be created and error will be printed instead. DocImpact Closes-Bug: #1324067 Change-Id: I5d41fb2bbeb4e56213ae8696b84bf96b749414f8
Diffstat (limited to 'glanceclient/v2/shell.py')
-rw-r--r--glanceclient/v2/shell.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py
index 238fcd3..4da2d99 100644
--- a/glanceclient/v2/shell.py
+++ b/glanceclient/v2/shell.py
@@ -41,6 +41,12 @@ def get_image_schema():
@utils.arg('--property', metavar="<key=value>", action='append',
default=[], help=('Arbitrary property to associate with image.'
' May be used multiple times.'))
+@utils.arg('--file', metavar='<FILE>',
+ help='Local file to save downloaded image data to. '
+ 'If this is not specified the image data will be '
+ 'written to stdout.')
+@utils.arg('--progress', action='store_true', default=False,
+ help='Show upload progress bar.')
def do_image_create(gc, args):
"""Create a new image."""
schema = gc.schemas.get("image")
@@ -55,8 +61,19 @@ def do_image_create(gc, args):
key, value = datum.split('=', 1)
fields[key] = value
+ file_name = fields.pop('file', None)
+ if file_name is not None and os.access(file_name, os.R_OK) is False:
+ utils.exit("File %s does not exist or user does not have read "
+ "privileges to it" % file_name)
image = gc.images.create(**fields)
- utils.print_image(image)
+ try:
+ if file_name is not None:
+ args.id = image['id']
+ args.size = None
+ do_image_upload(gc, args)
+ image = gc.images.get(args.id)
+ finally:
+ utils.print_image(image)
@utils.arg('id', metavar='<IMAGE_ID>', help='ID of image to update.')