summaryrefslogtreecommitdiff
path: root/glanceclient/v1
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-03-04 17:05:02 +0000
committerGerrit Code Review <review@openstack.org>2015-03-04 17:05:02 +0000
commite6d2f637ed4c192968a82b3af5bc48b6a44751da (patch)
tree575bc8bbbb3bc07b680c0cbf9ea3f616bf3e01b9 /glanceclient/v1
parentab52bf3ce2a2a7e42b48b499b56741d6dbe7c0df (diff)
parentaf29e0a1b0185caa61c3aed30c35a2d8f0e216cc (diff)
downloadpython-glanceclient-e6d2f637ed4c192968a82b3af5bc48b6a44751da.tar.gz
Merge "Show error on trying to upload to non-queued image"
Diffstat (limited to 'glanceclient/v1')
-rw-r--r--glanceclient/v1/shell.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py
index 4c6591a..92bdd01 100644
--- a/glanceclient/v1/shell.py
+++ b/glanceclient/v1/shell.py
@@ -17,6 +17,7 @@ from __future__ import print_function
import copy
import functools
+import os
import six
from oslo_utils import encodeutils
@@ -244,6 +245,17 @@ def do_image_create(gc, args):
_image_show(image, args.human_readable)
+def _is_image_data_provided(args):
+ """Return True if some image data has probably been provided by the user"""
+ # NOTE(kragniz): Check stdin works, then check is there is any data
+ # on stdin or a filename has been provided with --file
+ try:
+ os.fstat(0)
+ except OSError:
+ return False
+ return not sys.stdin.isatty() or args.file or args.copy_from
+
+
@utils.arg('image', metavar='<IMAGE>', help='Name or ID of image to modify.')
@utils.arg('--name', metavar='<NAME>',
help='Name of image.')
@@ -322,6 +334,12 @@ def do_image_update(gc, args):
fields['data'], filesize
)
+ elif _is_image_data_provided(args):
+ # NOTE(kragniz): Exit with an error if the status is not queued
+ # and image data was provided
+ utils.exit('Unable to upload image data to an image which '
+ 'is %s.' % image.status)
+
image = gc.images.update(image, purge_props=args.purge_props, **fields)
_image_show(image, args.human_readable)