Use suitable api version for OSC.

In manilaclient i.e. manila commands, if user supplied version is above
the max version supported by server, manilaclient adjust to max version.
This was missing in openstack commands which results in failure that
version is not supported. Fix by discovering most suitable version and
use it for client creation.

Closes-bug: #1960490
Change-Id: I734f6953e8b0266b38f0cb6e1581c4201f2bd676
This commit is contained in:
Kiran Pawar 2023-02-21 11:03:51 +00:00
parent 5abe263463
commit 95763cdb05
2 changed files with 35 additions and 20 deletions

View File

@ -20,6 +20,7 @@ import logging
from osc_lib import utils
from manilaclient import api_versions
from manilaclient import client
from manilaclient.common import constants
from manilaclient import exceptions
@ -60,35 +61,42 @@ def make_client(instance):
"""Returns a shared file system service client."""
requested_api_version = instance._api_version[API_NAME]
shared_file_system_client = utils.get_client_class(
API_NAME, requested_api_version, API_VERSIONS)
service_type, manila_endpoint_url = _get_manila_url_from_service_catalog(
instance)
instance.setup_auth()
debugging_enabled = instance._cli_options.debug
client_args = dict(session=instance.session,
service_catalog_url=manila_endpoint_url,
endpoint_type=instance.interface,
region_name=instance.region_name,
service_type=service_type,
auth=instance.auth,
http_log_debug=debugging_enabled,
cacert=instance.cacert,
cert=instance.cert,
insecure=not instance.verify)
# Cast the API version into an object for further processing
requested_api_version = api_versions.APIVersion(
version_str=requested_api_version)
max_version = api_versions.APIVersion(api_versions.MAX_VERSION)
client_args.update(dict(api_version=max_version))
temp_client = client.Client(max_version, **client_args)
discovered_version = api_versions.discover_version(temp_client,
requested_api_version)
shared_file_system_client = utils.get_client_class(
API_NAME, discovered_version.get_string(), API_VERSIONS)
LOG.debug('Instantiating Shared File System (share) client: %s',
shared_file_system_client)
LOG.debug('Shared File System API version: %s',
requested_api_version)
discovered_version)
service_type, manila_endpoint_url = _get_manila_url_from_service_catalog(
instance)
instance.setup_auth()
debugging_enabled = instance._cli_options.debug
client = shared_file_system_client(session=instance.session,
service_catalog_url=manila_endpoint_url,
endpoint_type=instance.interface,
region_name=instance.region_name,
service_type=service_type,
auth=instance.auth,
http_log_debug=debugging_enabled,
api_version=requested_api_version,
cacert=instance.cacert,
cert=instance.cert,
insecure=not instance.verify)
return client
client_args.update(dict(api_version=discovered_version))
return shared_file_system_client(**client_args)
def build_option_parser(parser):

View File

@ -0,0 +1,7 @@
---
fixes:
- |
The OpenStackClient plugin will now use most suitable version for
openstack commmands client generation if user supplied version is above
max version supported by server. For more details, please refer `Launchpad
bug #1960490 <https://bugs.launchpad.net/python-manilaclient/+bug/1960490>`_