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
This commit is contained in:
Erno Kuvaja
2014-10-14 16:23:45 +00:00
parent 3b6754a8cc
commit 8e02b2a641
2 changed files with 61 additions and 1 deletions
+18 -1
View File
@@ -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.')