summaryrefslogtreecommitdiff
path: root/openstackclient/image
diff options
context:
space:
mode:
authorwhoami-rajat <rajatdhasmana@gmail.com>2022-06-01 14:51:29 +0530
committerStephen Finucane <sfinucan@redhat.com>2022-07-04 12:30:08 +0100
commit665d93ff0721801896bf08c3cc4f189a55daae80 (patch)
tree6296bf50dc55ed0f7bf8426b41a3c5d78a143422 /openstackclient/image
parentcbc64f9469600624e74631f42ca214487e800155 (diff)
downloadpython-openstackclient-665d93ff0721801896bf08c3cc4f189a55daae80.tar.gz
Fix: create image from volume command
Currently the command ``openstack image create --volume`` calls cinderclient to upload the volume to image service (glance) but OSC passes ``visibility`` and ``protected`` fields which are only available in microversion 3.1 or greater. This generates an error if the user is using volume microversion < 3.1 and wants to create an image from volume. This patch fixes that by only passing ``visibility`` and ``protected`` fields when the volume microversion is 3.1 or greater and fail otherwise i.e. the following 3 cases: 1) visibility/protected argument + mv >= 3.1 = pass 2) visibility/protected argument + mv < 3.1 = fail 3) not visibility/protected argument + any mv = pass Story: 2010060 Task: 45511 Change-Id: I568a0ea0af8f7f82b16d49a6a1bb0391b99c50dc (cherry picked from commit 9eea28ba59e44526b9d6f1ad9f80c3553d5853e2) (cherry picked from commit 849e7e93f83a220265d11af71e2edc009c3f7bea)
Diffstat (limited to 'openstackclient/image')
-rw-r--r--openstackclient/image/v2/image.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index c1f46d2d..7c5b2ecf 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -21,6 +21,7 @@ import logging
import os
import sys
+from cinderclient import api_versions
import openstack.cloud._utils
from openstack.image import image_signer
from osc_lib.api import utils as api_utils
@@ -484,14 +485,27 @@ class CreateImage(command.ShowOne):
volume_client.volumes,
parsed_args.volume,
)
+ mv_kwargs = {}
+ if volume_client.api_version >= api_versions.APIVersion('3.1'):
+ mv_kwargs.update(
+ visibility=kwargs.get('visibility', 'private'),
+ protected=bool(parsed_args.protected)
+ )
+ else:
+ if kwargs.get('visibility') or parsed_args.protected:
+ msg = _(
+ '--os-volume-api-version 3.1 or greater is required '
+ 'to support the --public, --private, --community, '
+ '--shared or --protected option.'
+ )
+ raise exceptions.CommandError(msg)
response, body = volume_client.volumes.upload_to_image(
source_volume.id,
parsed_args.force,
parsed_args.name,
parsed_args.container_format,
parsed_args.disk_format,
- visibility=kwargs.get('visibility', 'private'),
- protected=True if parsed_args.protected else False
+ **mv_kwargs
)
info = body['os-volume_upload_image']
try: