create_image: support other import methods

Change-Id: I31a09f3906ec506d93d65e3209a813df1319e1e3
Signed-off-by: Cyril Roelandt <cyril@redhat.com>
This commit is contained in:
Mridula Joshi
2024-02-26 10:51:18 +00:00
committed by Cyril Roelandt
parent e933864149
commit b2ada579ce
4 changed files with 95 additions and 4 deletions

View File

@@ -131,6 +131,11 @@ class Proxy(proxy.Proxy):
timeout=3600, timeout=3600,
validate_checksum=False, validate_checksum=False,
use_import=False, use_import=False,
import_method=None,
uri=None,
remote_region=None,
remote_image_id=None,
remote_service_interface=None,
stores=None, stores=None,
all_stores=None, all_stores=None,
all_stores_must_succeed=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 cloud to transform image format. If the cloud has disabled direct
uploads, this will default to true. If you wish to use other import uploads, this will default to true. If you wish to use other import
methods, use the ``import_image`` method instead. 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 :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 activated in glance. List values can be the id of a store or a
:class:`~openstack.image.v2.service_info.Store` instance. :class:`~openstack.image.v2.service_info.Store` instance.
@@ -322,7 +341,7 @@ class Proxy(proxy.Proxy):
if tags: if tags:
image_kwargs['tags'] = tags image_kwargs['tags'] = tags
if filename or data: if filename or data or import_method:
image = self._upload_image( image = self._upload_image(
name, name,
filename=filename, filename=filename,
@@ -332,6 +351,11 @@ class Proxy(proxy.Proxy):
timeout=timeout, timeout=timeout,
validate_checksum=validate_checksum, validate_checksum=validate_checksum,
use_import=use_import, 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, stores=stores,
all_stores=all_stores, all_stores=all_stores,
all_stores_must_succeed=all_stores_must_succeed, all_stores_must_succeed=all_stores_must_succeed,
@@ -547,6 +571,11 @@ class Proxy(proxy.Proxy):
timeout=None, timeout=None,
validate_checksum=True, validate_checksum=True,
use_import=False, use_import=False,
import_method=None,
uri=None,
remote_region=None,
remote_image_id=None,
remote_service_interface=None,
stores=None, stores=None,
all_stores=None, all_stores=None,
all_stores_must_succeed=None, all_stores_must_succeed=None,
@@ -589,6 +618,11 @@ class Proxy(proxy.Proxy):
meta=meta, meta=meta,
validate_checksum=validate_checksum, validate_checksum=validate_checksum,
use_import=use_import, 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, stores=stores,
all_stores=all_stores, all_stores=all_stores,
all_stores_must_succeed=all_stores_must_succeed, all_stores_must_succeed=all_stores_must_succeed,
@@ -623,11 +657,21 @@ class Proxy(proxy.Proxy):
meta, meta,
validate_checksum, validate_checksum,
use_import=False, use_import=False,
import_method=None,
uri=None,
remote_region=None,
remote_image_id=None,
remote_service_interface=None,
stores=None, stores=None,
all_stores=None, all_stores=None,
all_stores_must_succeed=None, all_stores_must_succeed=None,
**image_kwargs, **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 # use of any of these imply use_import=True
if stores or all_stores or all_stores_must_succeed: if stores or all_stores or all_stores_must_succeed:
use_import = True use_import = True
@@ -647,7 +691,7 @@ class Proxy(proxy.Proxy):
supports_import = ( supports_import = (
image.image_import_methods 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: if use_import and not supports_import:
raise exceptions.SDKException( raise exceptions.SDKException(
@@ -660,8 +704,23 @@ class Proxy(proxy.Proxy):
response = image.upload(self) response = image.upload(self)
exceptions.raise_from_response(response) exceptions.raise_from_response(response)
if use_import: if use_import:
image.stage(self) kwargs = {}
image.import_image(self) 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 # image_kwargs are flat here
md5 = image_kwargs.get(self._IMAGE_MD5_KEY) md5 = image_kwargs.get(self._IMAGE_MD5_KEY)

View File

@@ -754,6 +754,7 @@ class TestImage(BaseTestImage):
is_public=False, is_public=False,
validate_checksum=True, validate_checksum=True,
use_import=True, use_import=True,
import_method='glance-direct',
) )
self.assert_calls() self.assert_calls()

View File

@@ -145,6 +145,11 @@ class TestImage(TestImageProxy):
'validate_checksum': False, 'validate_checksum': False,
'use_import': False, 'use_import': False,
'stores': None, 'stores': None,
'import_method': None,
'uri': None,
'remote_region': None,
'remote_image_id': None,
'remote_service_interface': None,
'all_stores': None, 'all_stores': None,
'all_stores_must_succeed': None, 'all_stores_must_succeed': None,
'disk_format': 'qcow2', 'disk_format': 'qcow2',
@@ -255,6 +260,11 @@ class TestImage(TestImageProxy):
timeout=3600, timeout=3600,
validate_checksum=True, validate_checksum=True,
use_import=False, use_import=False,
import_method=None,
uri=None,
remote_region=None,
remote_image_id=None,
remote_service_interface=None,
stores=None, stores=None,
all_stores=None, all_stores=None,
all_stores_must_succeed=None, all_stores_must_succeed=None,
@@ -303,6 +313,11 @@ class TestImage(TestImageProxy):
timeout=3600, timeout=3600,
validate_checksum=False, validate_checksum=False,
use_import=False, use_import=False,
import_method=None,
uri=None,
remote_region=None,
remote_image_id=None,
remote_service_interface=None,
stores=None, stores=None,
all_stores=None, all_stores=None,
all_stores_must_succeed=None, all_stores_must_succeed=None,
@@ -365,6 +380,11 @@ class TestImage(TestImageProxy):
timeout=3600, timeout=3600,
validate_checksum=False, validate_checksum=False,
use_import=True, use_import=True,
import_method=None,
uri=None,
remote_region=None,
remote_image_id=None,
remote_service_interface=None,
stores=['cinder', 'swift'], stores=['cinder', 'swift'],
all_stores=None, all_stores=None,
all_stores_must_succeed=None, all_stores_must_succeed=None,
@@ -402,6 +422,11 @@ class TestImage(TestImageProxy):
timeout=3600, timeout=3600,
validate_checksum=False, validate_checksum=False,
use_import=True, use_import=True,
import_method=None,
uri=None,
remote_region=None,
remote_image_id=None,
remote_service_interface=None,
stores=None, stores=None,
all_stores=True, all_stores=True,
all_stores_must_succeed=True, all_stores_must_succeed=True,

View File

@@ -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.