From b2ada579cecf45e04d19a3de60b073ac09c51fc5 Mon Sep 17 00:00:00 2001 From: Mridula Joshi Date: Mon, 26 Feb 2024 10:51:18 +0000 Subject: [PATCH] create_image: support other import methods Change-Id: I31a09f3906ec506d93d65e3209a813df1319e1e3 Signed-off-by: Cyril Roelandt --- openstack/image/v2/_proxy.py | 67 +++++++++++++++++-- openstack/tests/unit/cloud/test_image.py | 1 + openstack/tests/unit/image/v2/test_proxy.py | 25 +++++++ ...t-all-import-methods-48e4e382b7091dd3.yaml | 6 ++ 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/create-image-support-all-import-methods-48e4e382b7091dd3.yaml diff --git a/openstack/image/v2/_proxy.py b/openstack/image/v2/_proxy.py index 6b017ee46..988ef1f86 100644 --- a/openstack/image/v2/_proxy.py +++ b/openstack/image/v2/_proxy.py @@ -131,6 +131,11 @@ class Proxy(proxy.Proxy): timeout=3600, validate_checksum=False, use_import=False, + import_method=None, + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, stores=None, all_stores=None, all_stores_must_succeed=None, @@ -198,6 +203,20 @@ class Proxy(proxy.Proxy): cloud to transform image format. If the cloud has disabled direct uploads, this will default to true. If you wish to use other import methods, use the ``import_image`` method instead. + :param import_method: Method to use for importing the image. Not all + deployments support all methods. One of: ``glance-direct`` + (default), ``web-download``, ``glance-download`` (``copy-image`` is + not used with create). Use of ``glance-direct`` requires the image + be first staged. + :param uri: Required only if using the ``web-download`` import method. + This url is where the data is made available to the Image + service. + :param remote_region: The remote glance region to download the image + from when using glance-download. + :param remote_image_id: The ID of the image to import from the + remote glance when using glance-download. + :param remote_service_interface: The remote glance service interface to + use when using glance-download. :param stores: List of stores to be used when enabled_backends is activated in glance. List values can be the id of a store or a :class:`~openstack.image.v2.service_info.Store` instance. @@ -322,7 +341,7 @@ class Proxy(proxy.Proxy): if tags: image_kwargs['tags'] = tags - if filename or data: + if filename or data or import_method: image = self._upload_image( name, filename=filename, @@ -332,6 +351,11 @@ class Proxy(proxy.Proxy): timeout=timeout, validate_checksum=validate_checksum, use_import=use_import, + import_method=import_method, + uri=uri, + remote_region=remote_region, + remote_image_id=remote_image_id, + remote_service_interface=remote_service_interface, stores=stores, all_stores=all_stores, all_stores_must_succeed=all_stores_must_succeed, @@ -547,6 +571,11 @@ class Proxy(proxy.Proxy): timeout=None, validate_checksum=True, use_import=False, + import_method=None, + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, stores=None, all_stores=None, all_stores_must_succeed=None, @@ -589,6 +618,11 @@ class Proxy(proxy.Proxy): meta=meta, validate_checksum=validate_checksum, use_import=use_import, + import_method=import_method, + uri=uri, + remote_region=remote_region, + remote_image_id=remote_image_id, + remote_service_interface=remote_service_interface, stores=stores, all_stores=all_stores, all_stores_must_succeed=all_stores_must_succeed, @@ -623,11 +657,21 @@ class Proxy(proxy.Proxy): meta, validate_checksum, use_import=False, + import_method=None, + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, stores=None, all_stores=None, all_stores_must_succeed=None, **image_kwargs, ): + if all_stores and stores: + raise exceptions.InvalidRequest( + "all_stores is mutually exclusive with stores" + ) + # use of any of these imply use_import=True if stores or all_stores or all_stores_must_succeed: use_import = True @@ -647,7 +691,7 @@ class Proxy(proxy.Proxy): supports_import = ( image.image_import_methods - and 'glance-direct' in image.image_import_methods + and import_method in image.image_import_methods ) if use_import and not supports_import: raise exceptions.SDKException( @@ -660,8 +704,23 @@ class Proxy(proxy.Proxy): response = image.upload(self) exceptions.raise_from_response(response) if use_import: - image.stage(self) - image.import_image(self) + kwargs = {} + if stores is not None: + kwargs['stores'] = stores + else: + kwargs['all_stores'] = all_stores + kwargs['all_stores_must_succeed'] = all_stores_must_succeed + if import_method == 'glance-direct': + image.stage(self) + elif import_method == 'web-download': + kwargs['uri'] = uri + elif import_method == 'glance-download': + kwargs.update( + remote_region=remote_region, + remote_image_id=remote_image_id, + remote_service_interface=remote_service_interface, + ) + self.import_image(image, method=import_method, **kwargs) # image_kwargs are flat here md5 = image_kwargs.get(self._IMAGE_MD5_KEY) diff --git a/openstack/tests/unit/cloud/test_image.py b/openstack/tests/unit/cloud/test_image.py index aaec255ee..cf3ef15cc 100644 --- a/openstack/tests/unit/cloud/test_image.py +++ b/openstack/tests/unit/cloud/test_image.py @@ -754,6 +754,7 @@ class TestImage(BaseTestImage): is_public=False, validate_checksum=True, use_import=True, + import_method='glance-direct', ) self.assert_calls() diff --git a/openstack/tests/unit/image/v2/test_proxy.py b/openstack/tests/unit/image/v2/test_proxy.py index c4644ef75..3ce35672e 100644 --- a/openstack/tests/unit/image/v2/test_proxy.py +++ b/openstack/tests/unit/image/v2/test_proxy.py @@ -145,6 +145,11 @@ class TestImage(TestImageProxy): 'validate_checksum': False, 'use_import': False, 'stores': None, + 'import_method': None, + 'uri': None, + 'remote_region': None, + 'remote_image_id': None, + 'remote_service_interface': None, 'all_stores': None, 'all_stores_must_succeed': None, 'disk_format': 'qcow2', @@ -255,6 +260,11 @@ class TestImage(TestImageProxy): timeout=3600, validate_checksum=True, use_import=False, + import_method=None, + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, stores=None, all_stores=None, all_stores_must_succeed=None, @@ -303,6 +313,11 @@ class TestImage(TestImageProxy): timeout=3600, validate_checksum=False, use_import=False, + import_method=None, + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, stores=None, all_stores=None, all_stores_must_succeed=None, @@ -365,6 +380,11 @@ class TestImage(TestImageProxy): timeout=3600, validate_checksum=False, use_import=True, + import_method=None, + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, stores=['cinder', 'swift'], all_stores=None, all_stores_must_succeed=None, @@ -402,6 +422,11 @@ class TestImage(TestImageProxy): timeout=3600, validate_checksum=False, use_import=True, + import_method=None, + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, stores=None, all_stores=True, all_stores_must_succeed=True, diff --git a/releasenotes/notes/create-image-support-all-import-methods-48e4e382b7091dd3.yaml b/releasenotes/notes/create-image-support-all-import-methods-48e4e382b7091dd3.yaml new file mode 100644 index 000000000..f42ea61ef --- /dev/null +++ b/releasenotes/notes/create-image-support-all-import-methods-48e4e382b7091dd3.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The ``create_image`` method now takes new parameters (``import_method``, + ``uri``, ``remote_region``, ``remote_image_id`` and + ``remote_service_interface``) to support all import methods from Glance.