Skip to content

Commit c9e4e54

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Permit use of tuple API_VERSIONS"
2 parents 77143f9 + b2eccdc commit c9e4e54

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

openstackclient/compute/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
1514

1615
import logging
1716

@@ -21,13 +20,11 @@
2120

2221
LOG = logging.getLogger(__name__)
2322

23+
# global variables used when building the shell
2424
DEFAULT_API_VERSION = '2.1'
2525
API_VERSION_OPTION = 'os_compute_api_version'
2626
API_NAME = 'compute'
27-
API_VERSIONS = {
28-
'2': 'openstack.connection.Connection',
29-
'2.1': 'openstack.connection.Connection',
30-
}
27+
API_VERSIONS = ('2', '2.1')
3128

3229

3330
def make_client(instance):

openstackclient/identity/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
1514

1615
import logging
1716

@@ -20,9 +19,9 @@
2019

2120
from openstackclient.i18n import _
2221

23-
2422
LOG = logging.getLogger(__name__)
2523

24+
# global variables used when building the shell
2625
DEFAULT_API_VERSION = '3'
2726
API_VERSION_OPTION = 'os_identity_api_version'
2827
API_NAME = 'identity'

openstackclient/image/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
1514

1615
import logging
1716

@@ -21,13 +20,11 @@
2120

2221
LOG = logging.getLogger(__name__)
2322

23+
# global variables used when building the shell
2424
DEFAULT_API_VERSION = '2'
2525
API_VERSION_OPTION = 'os_image_api_version'
2626
API_NAME = 'image'
27-
API_VERSIONS = {
28-
'1': 'openstack.connection.Connection',
29-
'2': 'openstack.connection.Connection',
30-
}
27+
API_VERSIONS = ('1', '2')
3128

3229

3330
def make_client(instance):

openstackclient/network/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@
99
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
12-
#
1312

1413
import logging
1514

1615
from osc_lib import utils
1716

1817
from openstackclient.i18n import _
1918

20-
2119
LOG = logging.getLogger(__name__)
2220

21+
# global variables used when building the shell
2322
DEFAULT_API_VERSION = '2.0'
2423
API_VERSION_OPTION = 'os_network_api_version'
25-
API_NAME = "network"
26-
API_VERSIONS = {
27-
"2.0": "openstack.connection.Connection",
28-
"2": "openstack.connection.Connection",
29-
}
24+
API_NAME = 'network'
25+
API_VERSIONS = ('2.0', '2')
3026

3127

3228
def make_client(instance):

openstackclient/object/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
from openstackclient.api import object_store_v1
2121

22+
# global variables used when building the shell
2223
DEFAULT_API_VERSION = '1'
2324
API_VERSION_OPTION = 'os_object_api_version'
2425
API_NAME = 'object_store'
25-
API_VERSIONS = {
26-
'1': 'openstackclient.object.client.ObjectClientv1',
27-
}
26+
API_VERSIONS = ('1',)
2827

2928

3029
def make_client(instance):

openstackclient/shell.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,34 @@ def _load_plugins(self):
8888
# this throws an exception if invalid
8989
skip_old_check = mod_check_api_version(version_opt)
9090

91+
# NOTE(stephenfin): API_VERSIONS has traditionally been a
92+
# dictionary but the values are only used internally and are
93+
# ignored for the modules using SDK. So we now support tuples
94+
# instead.
9195
mod_versions = getattr(mod, 'API_VERSIONS', None)
92-
if not skip_old_check and mod_versions:
96+
if mod_versions is not None and not isinstance(
97+
mod_versions, (dict, tuple)
98+
):
99+
raise TypeError(
100+
f'Plugin {mod} has incompatible API_VERSIONS. '
101+
f'Expected: tuple, dict. Got: {type(mod_versions)}. '
102+
f'Please report this to your package maintainer.'
103+
)
104+
105+
if mod_versions and not skip_old_check:
93106
if version_opt not in mod_versions:
94107
sorted_versions = sorted(
95-
mod.API_VERSIONS.keys(),
108+
list(mod.API_VERSIONS),
96109
key=lambda s: list(map(int, s.split('.'))),
97110
)
98111
self.log.warning(
99-
"{} version {} is not in supported versions: {}".format(
100-
api, version_opt, ', '.join(sorted_versions)
101-
)
112+
"%(name)s API version %(version)s is not in "
113+
"supported versions: %(supported)s",
114+
{
115+
'name': api,
116+
'version': version_opt,
117+
'supported': ', '.join(sorted_versions),
118+
},
102119
)
103120

104121
# Command groups deal only with major versions

0 commit comments

Comments
 (0)