Merge "Permit use of tuple API_VERSIONS"
This commit is contained in:
@ -11,7 +11,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import logging
|
||||
|
||||
@ -21,13 +20,11 @@ from openstackclient.i18n import _
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# global variables used when building the shell
|
||||
DEFAULT_API_VERSION = '2.1'
|
||||
API_VERSION_OPTION = 'os_compute_api_version'
|
||||
API_NAME = 'compute'
|
||||
API_VERSIONS = {
|
||||
'2': 'openstack.connection.Connection',
|
||||
'2.1': 'openstack.connection.Connection',
|
||||
}
|
||||
API_VERSIONS = ('2', '2.1')
|
||||
|
||||
|
||||
def make_client(instance):
|
||||
|
@ -11,7 +11,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import logging
|
||||
|
||||
@ -20,9 +19,9 @@ from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# global variables used when building the shell
|
||||
DEFAULT_API_VERSION = '3'
|
||||
API_VERSION_OPTION = 'os_identity_api_version'
|
||||
API_NAME = 'identity'
|
||||
|
@ -11,7 +11,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import logging
|
||||
|
||||
@ -21,13 +20,11 @@ from openstackclient.i18n import _
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# global variables used when building the shell
|
||||
DEFAULT_API_VERSION = '2'
|
||||
API_VERSION_OPTION = 'os_image_api_version'
|
||||
API_NAME = 'image'
|
||||
API_VERSIONS = {
|
||||
'1': 'openstack.connection.Connection',
|
||||
'2': 'openstack.connection.Connection',
|
||||
}
|
||||
API_VERSIONS = ('1', '2')
|
||||
|
||||
|
||||
def make_client(instance):
|
||||
|
@ -9,7 +9,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import logging
|
||||
|
||||
@ -17,16 +16,13 @@ from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# global variables used when building the shell
|
||||
DEFAULT_API_VERSION = '2.0'
|
||||
API_VERSION_OPTION = 'os_network_api_version'
|
||||
API_NAME = "network"
|
||||
API_VERSIONS = {
|
||||
"2.0": "openstack.connection.Connection",
|
||||
"2": "openstack.connection.Connection",
|
||||
}
|
||||
API_NAME = 'network'
|
||||
API_VERSIONS = ('2.0', '2')
|
||||
|
||||
|
||||
def make_client(instance):
|
||||
|
@ -19,12 +19,11 @@ from osc_lib import utils
|
||||
|
||||
from openstackclient.api import object_store_v1
|
||||
|
||||
# global variables used when building the shell
|
||||
DEFAULT_API_VERSION = '1'
|
||||
API_VERSION_OPTION = 'os_object_api_version'
|
||||
API_NAME = 'object_store'
|
||||
API_VERSIONS = {
|
||||
'1': 'openstackclient.object.client.ObjectClientv1',
|
||||
}
|
||||
API_VERSIONS = ('1',)
|
||||
|
||||
|
||||
def make_client(instance):
|
||||
|
@ -88,17 +88,34 @@ class OpenStackShell(shell.OpenStackShell):
|
||||
# this throws an exception if invalid
|
||||
skip_old_check = mod_check_api_version(version_opt)
|
||||
|
||||
# NOTE(stephenfin): API_VERSIONS has traditionally been a
|
||||
# dictionary but the values are only used internally and are
|
||||
# ignored for the modules using SDK. So we now support tuples
|
||||
# instead.
|
||||
mod_versions = getattr(mod, 'API_VERSIONS', None)
|
||||
if not skip_old_check and mod_versions:
|
||||
if mod_versions is not None and not isinstance(
|
||||
mod_versions, (dict, tuple)
|
||||
):
|
||||
raise TypeError(
|
||||
f'Plugin {mod} has incompatible API_VERSIONS. '
|
||||
f'Expected: tuple, dict. Got: {type(mod_versions)}. '
|
||||
f'Please report this to your package maintainer.'
|
||||
)
|
||||
|
||||
if mod_versions and not skip_old_check:
|
||||
if version_opt not in mod_versions:
|
||||
sorted_versions = sorted(
|
||||
mod.API_VERSIONS.keys(),
|
||||
list(mod.API_VERSIONS),
|
||||
key=lambda s: list(map(int, s.split('.'))),
|
||||
)
|
||||
self.log.warning(
|
||||
"{} version {} is not in supported versions: {}".format(
|
||||
api, version_opt, ', '.join(sorted_versions)
|
||||
)
|
||||
"%(name)s API version %(version)s is not in "
|
||||
"supported versions: %(supported)s",
|
||||
{
|
||||
'name': api,
|
||||
'version': version_opt,
|
||||
'supported': ', '.join(sorted_versions),
|
||||
},
|
||||
)
|
||||
|
||||
# Command groups deal only with major versions
|
||||
|
Reference in New Issue
Block a user