Validate input args before trying image download
Currently client is contacting glance service even if the caller has niether specified any redirection nor '--file' option. This unnecessary request although isn't causing any critical issues but can be avoided by simply doing input validation first. TrivialFix Change-Id: I841bebeda38814235079429eca0b1e5fd2f04dae
This commit is contained in:
@@ -278,6 +278,12 @@ def do_explain(gc, args):
|
||||
help=_('Show download progress bar.'))
|
||||
def do_image_download(gc, args):
|
||||
"""Download a specific image."""
|
||||
if sys.stdout.isatty() and (args.file is None):
|
||||
msg = ('No redirection or local file specified for downloaded image '
|
||||
'data. Please specify a local file with --file to save '
|
||||
'downloaded image or redirect output to another source.')
|
||||
utils.exit(msg)
|
||||
|
||||
try:
|
||||
body = gc.images.data(args.id)
|
||||
except (exc.HTTPForbidden, exc.HTTPException) as e:
|
||||
@@ -290,13 +296,8 @@ def do_image_download(gc, args):
|
||||
|
||||
if args.progress:
|
||||
body = progressbar.VerboseIteratorWrapper(body, len(body))
|
||||
if not (sys.stdout.isatty() and args.file is None):
|
||||
utils.save_image(body, args.file)
|
||||
else:
|
||||
msg = ('No redirection or local file specified for downloaded image '
|
||||
'data. Please specify a local file with --file to save '
|
||||
'downloaded image or redirect output to another source.')
|
||||
utils.exit(msg)
|
||||
|
||||
utils.save_image(body, args.file)
|
||||
|
||||
|
||||
@utils.arg('--file', metavar='<FILE>',
|
||||
|
||||
Reference in New Issue
Block a user