Allow image upload from local file to v1 API

Allow an image to be read from a local file as an alternative to
stdin (which remains the default).

Change-Id: I81070ded9c505df7924c4efd5ae54cf3c0fa534d
This commit is contained in:
Adam Gandelman
2012-06-25 19:04:28 -07:00
committed by Brian Waldon
parent e9b8f8ec2f
commit 2713ca1bdc
+12 -2
View File
@@ -66,6 +66,10 @@ def do_image_show(gc, args):
' For example, if the image data is stored in the filesystem' ' For example, if the image data is stored in the filesystem'
' local to the glance server at \'/usr/share/image.tar.gz\',' ' local to the glance server at \'/usr/share/image.tar.gz\','
' you would specify \'file:///usr/share/image.tar.gz\'.')) ' you would specify \'file:///usr/share/image.tar.gz\'.'))
@utils.arg('--file', metavar='<FILE>',
help=('Local file that contains disk image to be uploaded during'
' creation or update. Alternatively, images can be passed to'
' the client via stdin.'))
@utils.arg('--checksum', metavar='<CHECKSUM>', @utils.arg('--checksum', metavar='<CHECKSUM>',
help='Hash of image data used Glance can use for verification.') help='Hash of image data used Glance can use for verification.')
@utils.arg('--copy-from', metavar='<IMAGE_URL>', @utils.arg('--copy-from', metavar='<IMAGE_URL>',
@@ -96,7 +100,10 @@ def do_image_create(gc, args):
fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, fields.items())) fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, fields.items()))
if 'location' not in fields and 'copy_from' not in fields: if 'location' not in fields and 'copy_from' not in fields:
fields['data'] = sys.stdin if args.file:
fields['data'] = open(args.file, 'r')
else:
fields['data'] = sys.stdin
image = gc.images.create(**fields) image = gc.images.create(**fields)
_image_show(image) _image_show(image)
@@ -152,7 +159,10 @@ def do_image_update(gc, args):
fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items())) fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items()))
if 'location' not in fields and 'copy_from' not in fields: if 'location' not in fields and 'copy_from' not in fields:
fields['data'] = sys.stdin if args.fields:
fields['data'] = open(args.file, 'r')
else:
fields['data'] = sys.stdin
image = gc.images.update(image_id, **fields) image = gc.images.update(image_id, **fields)
_image_show(image) _image_show(image)