Merge "Allow to resize in-use volumes"

This commit is contained in:
Zuul 2020-11-17 14:51:42 +00:00 committed by Gerrit Code Review
commit 2005a1e833
2 changed files with 15 additions and 6 deletions

View File

@ -29,6 +29,7 @@ API_VERSIONS = {
"1": "cinderclient.v1.client.Client", "1": "cinderclient.v1.client.Client",
"2": "cinderclient.v2.client.Client", "2": "cinderclient.v2.client.Client",
"3": "cinderclient.v3.client.Client", "3": "cinderclient.v3.client.Client",
"3.42": "cinderclient.v3.client.Client",
} }
@ -47,14 +48,19 @@ def make_client(instance):
except Exception: except Exception:
del API_VERSIONS['1'] del API_VERSIONS['1']
if instance._api_version[API_NAME] == '1': version = instance._api_version[API_NAME]
from cinderclient import api_versions
# convert to APIVersion object
version = api_versions.get_api_version(version)
if version.ver_major == '1':
# Monkey patch for v1 cinderclient # Monkey patch for v1 cinderclient
volumes.Volume.NAME_ATTR = 'display_name' volumes.Volume.NAME_ATTR = 'display_name'
volume_snapshots.Snapshot.NAME_ATTR = 'display_name' volume_snapshots.Snapshot.NAME_ATTR = 'display_name'
volume_client = utils.get_client_class( volume_client = utils.get_client_class(
API_NAME, API_NAME,
instance._api_version[API_NAME], version.ver_major,
API_VERSIONS API_VERSIONS
) )
LOG.debug('Instantiating volume client: %s', volume_client) LOG.debug('Instantiating volume client: %s', volume_client)
@ -76,6 +82,7 @@ def make_client(instance):
http_log_debug=http_log_debug, http_log_debug=http_log_debug,
region_name=instance.region_name, region_name=instance.region_name,
endpoint_override=endpoint_override, endpoint_override=endpoint_override,
api_version=version,
**kwargs **kwargs
) )

View File

@ -605,14 +605,16 @@ class SetVolume(command.Command):
result = 0 result = 0
if parsed_args.size: if parsed_args.size:
try: try:
if volume.status != 'available':
msg = (_("Volume is in %s state, it must be available "
"before size can be extended") % volume.status)
raise exceptions.CommandError(msg)
if parsed_args.size <= volume.size: if parsed_args.size <= volume.size:
msg = (_("New size must be greater than %s GB") msg = (_("New size must be greater than %s GB")
% volume.size) % volume.size)
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)
if volume.status != 'available' and \
not volume_client.api_version.matches('3.42'):
msg = (_("Volume is in %s state, it must be available "
"before size can be extended") % volume.status)
raise exceptions.CommandError(msg)
volume_client.volumes.extend(volume.id, parsed_args.size) volume_client.volumes.extend(volume.id, parsed_args.size)
except Exception as e: except Exception as e:
LOG.error(_("Failed to set volume size: %s"), e) LOG.error(_("Failed to set volume size: %s"), e)