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
This commit is contained in:
Miles Gould 2016-01-15 11:56:57 +00:00
parent 6849d17352
commit 429b88e152
3 changed files with 15 additions and 71 deletions

View File

@ -1,51 +0,0 @@
# Copyright 2010 Jacob Kaplan-Moss
# Copyright 2011 OpenStack Foundation
# Copyright 2011 Piston Cloud Computing, Inc.
#
# Modified by: Brad P. Crochet <brad@redhat.com>
#
# 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)

View File

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

View File

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