From 429b88e1522fda7471665e243db13b20d1e30ee0 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Fri, 15 Jan 2016 11:56:57 +0000 Subject: [PATCH] Support all API versions up to 1.latest Only 1.11 is a breaking change, and it's needed to support ENROLL state in python-tripleoclient. Adding support for all recent versions was no harder than adding support for one, since the version number is passed uninspected to the internal HTTP client in all cases. API versions 1.1--1.4 and 1.7--1.8 were previously unsupported, despite higher versions being supported. I couldn't see any reason for this (there are tests in the main Ironic codebase for the use of those minor versions), so I added those in too. The file ironicclient/osc/client.py seemed to just duplicate code from openstackclient.common.utils and add an extra level of indirection without providing any benefit. It also required the list of supported APIs to be maintained in two places, so rather than duplicate my changes I've removed it. Change-Id: I854515123c24903190e297dfc93813574fb99deb --- ironicclient/osc/client.py | 51 ------------------- ironicclient/osc/plugin.py | 30 ++++------- .../add_api_versions-a59e5b6899833c33.yaml | 5 ++ 3 files changed, 15 insertions(+), 71 deletions(-) delete mode 100644 ironicclient/osc/client.py create mode 100644 releasenotes/notes/add_api_versions-a59e5b6899833c33.yaml diff --git a/ironicclient/osc/client.py b/ironicclient/osc/client.py deleted file mode 100644 index 5beaebf32..000000000 --- a/ironicclient/osc/client.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2010 Jacob Kaplan-Moss -# Copyright 2011 OpenStack Foundation -# Copyright 2011 Piston Cloud Computing, Inc. -# -# Modified by: Brad P. Crochet -# -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -OpenStack Client factory. -""" - -from oslo_utils import importutils - -from ironicclient.common.i18n import _ -from ironicclient import exceptions - - -def get_client_class(version): - version_map = { - '1': 'ironicclient.v1.client.Client', - '1.5': 'ironicclient.v1.client.Client', - '1.6': 'ironicclient.v1.client.Client', - '1.9': 'ironicclient.v1.client.Client', - } - try: - client_path = version_map[str(version)] - except (KeyError, ValueError): - msg = _("Invalid client version '%(version)s'. must be one of: " - "%(keys)s") % {'version': version, - 'keys': ', '.join(version_map)} - raise exceptions.UnsupportedVersion(msg) - - return importutils.import_class(client_path) - - -def Client(version, *args, **kwargs): - client_class = get_client_class(version) - return client_class(*args, **kwargs) diff --git a/ironicclient/osc/plugin.py b/ironicclient/osc/plugin.py index 4f6ba628f..fc16e99d0 100644 --- a/ironicclient/osc/plugin.py +++ b/ironicclient/osc/plugin.py @@ -16,40 +16,30 @@ import logging -from openstackclient.common import exceptions from openstackclient.common import utils -from ironicclient.common.i18n import _ -from ironicclient.osc import client as ironic_client - LOG = logging.getLogger(__name__) DEFAULT_BAREMETAL_API_VERSION = '1.6' API_VERSION_OPTION = 'os_baremetal_api_version' API_NAME = 'baremetal' +LAST_KNOWN_API_VERSION = 14 API_VERSIONS = { - '1': 'ironicclient.osc.client', - '1.5': 'ironicclient.osc.client', - '1.6': 'ironicclient.osc.client', - '1.9': 'ironicclient.osc.client', + '1.%d' % i: 'ironicclient.v1.client.Client' + for i in range(1, LAST_KNOWN_API_VERSION + 1) } +API_VERSIONS['1'] = API_VERSIONS[DEFAULT_BAREMETAL_API_VERSION] def make_client(instance): """Returns a baremetal service client.""" - try: - baremetal_client = ironic_client.get_client_class( - instance._api_version[API_NAME]) - except Exception: - msg = (_("Invalid %(api_name)s client version '%(ver)s'. Must be one " - "of %(supported_ver)s") % - {'api_name': API_NAME, - 'ver': instance._api_version[API_NAME], - 'supported_ver': ", ".join(sorted(API_VERSIONS))}) - raise exceptions.UnsupportedVersion(msg) - LOG.debug('Instantiating baremetal client: %s', baremetal_client) + baremetal_client_class = utils.get_client_class( + API_NAME, + instance._api_version[API_NAME], + API_VERSIONS) + LOG.debug('Instantiating baremetal client: %s', baremetal_client_class) - client = baremetal_client( + client = baremetal_client_class( os_ironic_api_version=instance._api_version[API_NAME], session=instance.session, region_name=instance._region_name, diff --git a/releasenotes/notes/add_api_versions-a59e5b6899833c33.yaml b/releasenotes/notes/add_api_versions-a59e5b6899833c33.yaml new file mode 100644 index 000000000..88ba9a58c --- /dev/null +++ b/releasenotes/notes/add_api_versions-a59e5b6899833c33.yaml @@ -0,0 +1,5 @@ +--- +features: + - Add support to the openstackclient plugin for all Ironic API versions of + the form 1.x, up to the latest known minor version. The regular Ironic CLI + already supports all known versions.