Skip to content

Commit 7ae49c5

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add command to show all service versions"
2 parents cc037e2 + 9ece632 commit 7ae49c5

5 files changed

Lines changed: 194 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
========
2+
versions
3+
========
4+
5+
Get a list of every version of every service in a given cloud.
6+
7+
versions show
8+
-------------
9+
10+
Show service versions:
11+
12+
.. program:: versions show
13+
.. code:: bash
14+
15+
openstack versions show
16+
[--all-interfaces]
17+
[--interface <interface>]
18+
[--region-name <region-name>]
19+
[--service <service>]
20+
21+
.. option:: --all-interfaces
22+
23+
Return results for every interface of every service.
24+
[Mutually exclusive with --interface]
25+
26+
.. option:: --interface <interface>
27+
28+
Limit results to only those on given interface.
29+
[Default 'public'. Mutually exclusive with --all-interfaces]
30+
31+
.. option:: --region-name <region-name>
32+
33+
Limit results to only those from region-name
34+
35+
.. option:: --service <service>
36+
37+
Limit results to only those for service. The argument should be either
38+
an exact match to what is in the catalog or a known official value or
39+
alias from `service-types-authority`_.
40+
41+
.. _service-types-authority: https://service-types.openstack.org/

openstackclient/common/versions.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Copyright 2018 Red Hat, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
"""Versions Action Implementation"""
16+
17+
import os_service_types
18+
from osc_lib.command import command
19+
20+
from openstackclient.i18n import _
21+
22+
23+
class ShowVersions(command.Lister):
24+
_description = _("Show available versions of services")
25+
26+
def get_parser(self, prog_name):
27+
parser = super(ShowVersions, self).get_parser(prog_name)
28+
interface_group = parser.add_mutually_exclusive_group()
29+
interface_group.add_argument(
30+
"--all-interfaces",
31+
dest="is_all_interfaces",
32+
action="store_true",
33+
default=False,
34+
help=_("Show values for all interfaces"),
35+
)
36+
interface_group.add_argument(
37+
'--interface',
38+
default='public',
39+
metavar='<interface>',
40+
help=_('Show versions for a specific interface.'),
41+
)
42+
parser.add_argument(
43+
'--region-name',
44+
metavar='<region_name>',
45+
help=_('Show versions for a specific region.'),
46+
)
47+
parser.add_argument(
48+
'--service',
49+
metavar='<region_name>',
50+
help=_('Show versions for a specific service.'),
51+
)
52+
parser.add_argument(
53+
'--status',
54+
metavar='<region_name>',
55+
help=_('Show versions for a specific status.'
56+
' [Valid values are SUPPORTED, CURRENT,'
57+
' DEPRECATED, EXPERIMENTAL]'),
58+
)
59+
return parser
60+
61+
def take_action(self, parsed_args):
62+
63+
interface = parsed_args.interface
64+
if parsed_args.is_all_interfaces:
65+
interface = None
66+
67+
session = self.app.client_manager.session
68+
version_data = session.get_all_version_data(
69+
interface=interface,
70+
region_name=parsed_args.region_name)
71+
72+
columns = [
73+
"Region Name",
74+
"Service Type",
75+
"Version",
76+
"Status",
77+
"Endpoint",
78+
"Min Microversion",
79+
"Max Microversion",
80+
]
81+
82+
status = parsed_args.status
83+
if status:
84+
status = status.upper()
85+
86+
service = parsed_args.service
87+
if service:
88+
# Normalize service type argument to official type
89+
service_type_manager = os_service_types.ServiceTypes()
90+
service = service_type_manager.get_service_type(service)
91+
92+
versions = []
93+
for region_name, interfaces in version_data.items():
94+
for interface, services in interfaces.items():
95+
for service_type, service_versions in services.items():
96+
if service and service != service_type:
97+
# TODO(mordred) Once there is a version of
98+
# keystoneauth that can do this filtering
99+
# before making all the discovery calls, switch
100+
# to that.
101+
continue
102+
for data in service_versions:
103+
if status and status != data['status']:
104+
continue
105+
versions.append((
106+
region_name,
107+
service_type,
108+
data['version'],
109+
data['status'],
110+
data['url'],
111+
data['min_microversion'],
112+
data['max_microversion'],
113+
))
114+
return (columns, versions)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import json
14+
15+
from openstackclient.tests.functional import base
16+
17+
18+
class VersionsTests(base.TestCase):
19+
"""Functional tests for versions."""
20+
21+
def test_versions_show(self):
22+
# TODO(mordred) Make this better. The trick is knowing what in the
23+
# payload to test for.
24+
cmd_output = json.loads(self.openstack(
25+
'versions show -f json'
26+
))
27+
self.assertIsNotNone(cmd_output)
28+
self.assertIn(
29+
"Region Name",
30+
cmd_output[0],
31+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
A new command, ``openstack versions show`` was added, which will
5+
provide a list of all versions of all services in the cloud. It
6+
includes relevant metadata, such as min/max microversion, endpoint,
7+
status and region.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ openstack.common =
5151
quota_list = openstackclient.common.quota:ListQuota
5252
quota_set = openstackclient.common.quota:SetQuota
5353
quota_show = openstackclient.common.quota:ShowQuota
54+
versions_show = openstackclient.common.versions:ShowVersions
5455

5556
openstack.compute.v2 =
5657
compute_agent_create = openstackclient.compute.v2.agent:CreateAgent

0 commit comments

Comments
 (0)