diff options
-rw-r--r-- | doc/source/cli/details.rst | 183 | ||||
-rw-r--r-- | glanceclient/shell.py | 12 | ||||
-rw-r--r-- | glanceclient/tests/unit/v2/test_shell_v2.py | 14 | ||||
-rw-r--r-- | glanceclient/v2/shell.py | 15 |
4 files changed, 207 insertions, 17 deletions
diff --git a/doc/source/cli/details.rst b/doc/source/cli/details.rst index 400c1ed..1348c81 100644 --- a/doc/source/cli/details.rst +++ b/doc/source/cli/details.rst @@ -5,7 +5,7 @@ Image service (glance) command-line client The glance client is the command-line interface (CLI) for the Image service (glance) API and its extensions. -This chapter documents :command:`glance` version ``2.7.0``. +This chapter documents :command:`glance` version ``2.8.0``. For help on a specific :command:`glance` command, enter: @@ -95,11 +95,11 @@ glance optional arguments HMAC key to use for encrypting context data for performance profiling of operation. This key should be the value of HMAC key configured in osprofiler - middleware in glance, it is specified in paste - configuration file at /etc/glance/api-paste.ini and - /etc/glance/registry-paste.ini. Without key the + middleware in glance, it is specified in glance + configuration file at /etc/glance/glance-api.conf and + /etc/glance/glance-registry.conf. Without key the profiling will not be triggered even if osprofiler is - enabled on server side. + enabled on server side. Defaults to ``env[OS_PROFILE]``. ``--key-file OS_KEY`` **DEPRECATED!** Use --os-key. @@ -555,6 +555,179 @@ Upload data for a specific image. ``--progress`` Show upload progress bar. +.. _glance_import-info: + +glance import-info +------------------ + +.. code-block:: console + + usage: glance import-info + +Prints the import methods available from Glance, or a message +if the target Glance does not support image import. + +.. _glance_image-stage: + +glance image-stage +------------------ + +.. code-block:: console + + usage: glance image-stage [--file <FILE>] [--size <IMAGE_SIZE>] + [--progress] + <IMAGE_ID> + +Upload data for a specific image to staging. + +**Positional arguments:** + +``<IMAGE_ID>`` + ID of image to upload data to. + +**Optional arguments:** + +``--file <FILE>`` + Local file that contains disk image to be uploaded. + Alternatively, images can be passed to the client via + stdin. + +``--size <IMAGE_SIZE>`` + Size in bytes of image to be uploaded. Default is to get size from + provided data object but this is supported in case where size cannot + be inferred. + +``--progress`` + Show upload progress bar. + +.. _glance_image-import: + +glance image-import +------------------- + +.. code-block:: console + + usage: glance image-import [--import-method <METHOD>] + <IMAGE_ID> + +Initiate the image import taskflow. + +**Positional arguments:** + +``<IMAGE_ID>`` + ID of image to import. + +**Optional arguments:** + +``--import-method <METHOD>`` + Import method used for Image Import workflow. Valid values can + be retrieved with import-info command and the default "glance-direct" + is used with "image-stage". + +.. _glance_image-create-via-import: + +glance image-create-via-import +------------------------------ + +This is an **EXPERIMENTAL** command. It may be renamed or removed in +future releases. + +.. code-block:: console + + usage: glance image-create-via import [--architecture <ARCHITECTURE>] + [--protected [True|False]] [--name <NAME>] + [--instance-uuid <INSTANCE_UUID>] + [--min-disk <MIN_DISK>] [--visibility <VISIBILITY>] + [--kernel-id <KERNEL_ID>] + [--tags <TAGS> [<TAGS> ...]] + [--os-version <OS_VERSION>] + [--disk-format <DISK_FORMAT>] + [--os-distro <OS_DISTRO>] [--id <ID>] + [--owner <OWNER>] [--ramdisk-id <RAMDISK_ID>] + [--min-ram <MIN_RAM>] + [--container-format <CONTAINER_FORMAT>] + [--property <key=value>] [--file <FILE>] + [--progress] + +Create a new image using the image import process. + +**NOTE** This is an EXPERIMENTAL command. It may be renamed or removed in +future releases. + +**Optional arguments:** + +``--architecture <ARCHITECTURE>`` + Operating system architecture as specified in + https://docs.openstack.org/glance/latest/user/common-image-properties.html#architecture + +``--protected [True|False]`` + If true, image will not be deletable. + +``--name <NAME>`` + Descriptive name for the image + +``--instance-uuid <INSTANCE_UUID>`` + Metadata which can be used to record which instance + this image is associated with. (Informational only, + does not create an instance snapshot.) + +``--min-disk <MIN_DISK>`` + Amount of disk space (in GB) required to boot image. + +``--visibility <VISIBILITY>`` + Scope of image accessibility Valid values: public, + private, community, shared + +``--kernel-id <KERNEL_ID>`` + ID of image stored in Glance that should be used as + the kernel when booting an AMI-style image. + +``--tags <TAGS> [<TAGS> ...]`` + List of strings related to the image + +``--os-version <OS_VERSION>`` + Operating system version as specified by the + distributor + +``--disk-format <DISK_FORMAT>`` + Format of the disk Valid values: None, ami, ari, aki, + vhd, vhdx, vmdk, raw, qcow2, vdi, iso, ploop + +``--os-distro <OS_DISTRO>`` + Common name of operating system distribution as + specified + in + https://docs.openstack.org/glance/latest/user/common-image-properties.html#os-distro + +``--id <ID>`` + An identifier for the image + +``--owner <OWNER>`` + Owner of the image + +``--ramdisk-id <RAMDISK_ID>`` + ID of image stored in Glance that should be used as + the ramdisk when booting an AMI-style image. + +``--min-ram <MIN_RAM>`` + Amount of ram (in MB) required to boot image. + +``--container-format <CONTAINER_FORMAT>`` + Format of the container Valid values: None, ami, ari, + aki, bare, ovf, ova, docker + +``--property <key=value>`` + Arbitrary property to associate with image. May be + used multiple times. + +``--file <FILE>`` + Local file that contains disk image to be uploaded + during creation. Alternatively, the image data can be + passed to the client via stdin. + +``--progress`` + Show upload progress bar. + .. _glance_location-add: glance location-add diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 55862cf..416d173 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -184,16 +184,18 @@ class OpenStackImagesShell(object): if osprofiler_profiler: parser.add_argument('--profile', metavar='HMAC_KEY', + default=utils.env('OS_PROFILE'), help='HMAC key to use for encrypting context ' 'data for performance profiling of operation. ' 'This key should be the value of HMAC key ' 'configured in osprofiler middleware in ' - 'glance, it is specified in paste ' + 'glance, it is specified in glance ' 'configuration file at ' - '/etc/glance/api-paste.ini and ' - '/etc/glance/registry-paste.ini. Without key ' - 'the profiling will not be triggered even ' - 'if osprofiler is enabled on server side.') + '/etc/glance/glance-api.conf and ' + '/etc/glance/glance-registry.conf. Without ' + 'key the profiling will not be triggered even ' + 'if osprofiler is enabled on server side. ' + 'Defaults to env[OS_PROFILE].') self._append_global_identity_args(parser, argv) diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py index fed1f72..4ac8c17 100644 --- a/glanceclient/tests/unit/v2/test_shell_v2.py +++ b/glanceclient/tests/unit/v2/test_shell_v2.py @@ -590,6 +590,20 @@ class ShellV2Test(testtools.TestCase): test_shell.do_image_download(self.gc, args) mocked_data.assert_called_once_with('IMG-01') + @mock.patch.object(utils, 'exit') + @mock.patch('sys.stdout', autospec=True) + def test_image_download_no_file_arg(self, mocked_stdout, + mocked_utils_exit): + # Indicate that no file name was given as command line argument + args = self._make_args({'id': '1234', 'file': None, 'progress': False}) + # Indicate that no file is specified for output redirection + mocked_stdout.isatty = lambda: True + test_shell.do_image_download(self.gc, args) + mocked_utils_exit.assert_called_once_with( + '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.') + def test_do_image_delete(self): args = argparse.Namespace(id=['image1', 'image2']) with mock.patch.object(self.gc.images, 'delete') as mocked_delete: diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 5354db4..9ce6f96 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -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>', |