From 6f616a29b300238c004b676edd98a5337be38193 Mon Sep 17 00:00:00 2001 From: youngho choi <0505zxc@gmail.com> Date: Mon, 7 Sep 2020 06:35:04 +0900 Subject: Add support '--progress' option for 'image create' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit openstack-client doesn’t support the upload progress bar. This patch shows progressbar when create image if you added '--progress' option like a python-glanceclient. like this. [=============================>] 100% +------------------+---------------------------+ | Field | Value | +------------------+---------------------------+ | container_format | bare | | created_at | 2020-09-06T20:44:40Z | ... How to use Add the'--progress' option on the 'openstack image create' command. Code was written by referring to 'python-glanceclient' project on stable/ussuri branch Change-Id: Ic3035b49da10b6555066eee607a14a5b73797c00 task: 40003 story: 2007777 --- openstackclient/image/v2/image.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'openstackclient/image') diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index fa7f4be5..71779293 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -30,6 +30,7 @@ from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils +from openstackclient.common import progressbar from openstackclient.common import sdk_utils from openstackclient.i18n import _ from openstackclient.identity import common @@ -255,6 +256,12 @@ class CreateImage(command.ShowOne): help=_("Force image creation if volume is in use " "(only meaningful with --volume)"), ) + parser.add_argument( + "--progress", + action="store_true", + default=False, + help=_("Show upload progress bar."), + ) parser.add_argument( '--sign-key-path', metavar="", @@ -412,6 +419,11 @@ class CreateImage(command.ShowOne): if fp is None and parsed_args.file: LOG.warning(_("Failed to get an image file.")) return {}, {} + if fp is not None and parsed_args.progress: + filesize = os.path.getsize(fname) + if filesize is not None: + kwargs['validate_checksum'] = False + kwargs['data'] = progressbar.VerboseFileWrapper(fp, filesize) elif fname: kwargs['filename'] = fname elif fp: -- cgit v1.2.1