summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2018-07-23 09:31:17 -0500
committerMonty Taylor <mordred@inaugust.com>2018-07-23 16:58:30 -0500
commit9ece632f96844fd78c2f717f2f6d35e61c3b9ef2 (patch)
tree24747b229075ea5b0b16b660074006f8da7020fe
parentee35409069b0f77984e912cfc0c90cb9cce52512 (diff)
Add command to show all service versions
Knowing what services and what versions of those services exist on a cloud isn't always a spectacular experience. Add a command that will use get_all_version_data from keystoneauth to produce a report of the available services and the version info for each service. Depends-On: https://review.openstack.org/584944 Change-Id: I84751c175d0c5f6d857a5473d2db6d5f1b41f946
Notes
Notes (review): Code-Review+2: Dean Troyer <dtroyer@gmail.com> Code-Review+1: yanpuqing <yanpq@awcloud.com> Workflow+1: Dean Troyer <dtroyer@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 25 Jul 2018 17:57:44 +0000 Reviewed-on: https://review.openstack.org/584905 Project: openstack/python-openstackclient Branch: refs/heads/master
-rw-r--r--doc/source/cli/command-objects/versions.rst41
-rw-r--r--openstackclient/common/versions.py114
-rw-r--r--openstackclient/tests/functional/common/test_versions.py31
-rw-r--r--releasenotes/notes/versions-show-12a2443624c83048.yaml7
-rw-r--r--setup.cfg1
5 files changed, 194 insertions, 0 deletions
diff --git a/doc/source/cli/command-objects/versions.rst b/doc/source/cli/command-objects/versions.rst
new file mode 100644
index 0000000..6742565
--- /dev/null
+++ b/doc/source/cli/command-objects/versions.rst
@@ -0,0 +1,41 @@
1========
2versions
3========
4
5Get a list of every version of every service in a given cloud.
6
7versions show
8-------------
9
10Show 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/
diff --git a/openstackclient/common/versions.py b/openstackclient/common/versions.py
new file mode 100644
index 0000000..6a93d30
--- /dev/null
+++ b/openstackclient/common/versions.py
@@ -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
17import os_service_types
18from osc_lib.command import command
19
20from openstackclient.i18n import _
21
22
23class 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)
diff --git a/openstackclient/tests/functional/common/test_versions.py b/openstackclient/tests/functional/common/test_versions.py
new file mode 100644
index 0000000..adc74eb
--- /dev/null
+++ b/openstackclient/tests/functional/common/test_versions.py
@@ -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
13import json
14
15from openstackclient.tests.functional import base
16
17
18class 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 )
diff --git a/releasenotes/notes/versions-show-12a2443624c83048.yaml b/releasenotes/notes/versions-show-12a2443624c83048.yaml
new file mode 100644
index 0000000..4f5652f
--- /dev/null
+++ b/releasenotes/notes/versions-show-12a2443624c83048.yaml
@@ -0,0 +1,7 @@
1---
2features:
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.
diff --git a/setup.cfg b/setup.cfg
index f9c0b3e..e2fd73b 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -51,6 +51,7 @@ openstack.common =
51 quota_list = openstackclient.common.quota:ListQuota 51 quota_list = openstackclient.common.quota:ListQuota
52 quota_set = openstackclient.common.quota:SetQuota 52 quota_set = openstackclient.common.quota:SetQuota
53 quota_show = openstackclient.common.quota:ShowQuota 53 quota_show = openstackclient.common.quota:ShowQuota
54 versions_show = openstackclient.common.versions:ShowVersions
54 55
55openstack.compute.v2 = 56openstack.compute.v2 =
56 compute_agent_create = openstackclient.compute.v2.agent:CreateAgent 57 compute_agent_create = openstackclient.compute.v2.agent:CreateAgent