|
| 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) |
0 commit comments