summaryrefslogtreecommitdiff
path: root/openstackclient/common/versions.py
blob: 3acd9f73d7eb884d15d1975abc007d8e7d80beb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Copyright 2018 Red Hat, Inc.
#
# 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.

"""Versions Action Implementation"""

from osc_lib.command import command

from openstackclient.i18n import _


class ShowVersions(command.Lister):
    _description = _("Show available versions of services")

    def get_parser(self, prog_name):
        parser = super(ShowVersions, self).get_parser(prog_name)
        interface_group = parser.add_mutually_exclusive_group()
        interface_group.add_argument(
            "--all-interfaces",
            dest="is_all_interfaces",
            action="store_true",
            default=False,
            help=_("Show values for all interfaces"),
        )
        interface_group.add_argument(
            '--interface',
            default='public',
            metavar='<interface>',
            help=_('Show versions for a specific interface.'),
        )
        parser.add_argument(
            '--region-name',
            metavar='<region_name>',
            help=_('Show versions for a specific region.'),
        )
        parser.add_argument(
            '--service',
            metavar='<service>',
            help=_('Show versions for a specific service. The argument should '
                   'be either an exact match to what is in the catalog or a '
                   'known official value or alias from '
                   'service-types-authority '
                   '(https://service-types.openstack.org/)'),
        )
        parser.add_argument(
            '--status',
            metavar='<status>',
            help=_("""Show versions for a specific status. Valid values are:

- SUPPORTED
- CURRENT
- DEPRECATED
- EXPERIMENTAL""")
        )
        return parser

    def take_action(self, parsed_args):

        interface = parsed_args.interface
        if parsed_args.is_all_interfaces:
            interface = None

        session = self.app.client_manager.session
        version_data = session.get_all_version_data(
            interface=interface,
            region_name=parsed_args.region_name,
            service_type=parsed_args.service)

        columns = [
            "Region Name",
            "Service Type",
            "Version",
            "Status",
            "Endpoint",
            "Min Microversion",
            "Max Microversion",
        ]

        status = parsed_args.status
        if status:
            status = status.upper()

        versions = []
        for region_name, interfaces in version_data.items():
            for interface, services in interfaces.items():
                for service_type, service_versions in services.items():
                    for data in service_versions:
                        if status and status != data['status']:
                            continue
                        versions.append((
                            region_name,
                            service_type,
                            data['version'],
                            data['status'],
                            data['url'],
                            data['min_microversion'],
                            data['max_microversion'],
                        ))
        return (columns, versions)