From dfd37a2e6e49fc547e7a2e8f7840561ece8ff46f Mon Sep 17 00:00:00 2001
From: Monty Taylor <mordred@inaugust.com>
Date: Mon, 23 Jul 2018 15:53:53 -0500
Subject: [PATCH] Make use of keystoneauth service-type filtering for versions

The first version of the versions show command does client-side
service-type filtering, which while functional, causes many more API
calls than needed. Now that keystoneauth supports the filtering at the
source, use it.

Change-Id: I57c49e67f9cb285a5f5bc19ec53a42d10de9f0da
---
 lower-constraints.txt              |  2 +-
 openstackclient/common/versions.py | 16 ++--------------
 requirements.txt                   |  2 +-
 3 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/lower-constraints.txt b/lower-constraints.txt
index db92fef36b..acd11d3238 100644
--- a/lower-constraints.txt
+++ b/lower-constraints.txt
@@ -38,7 +38,7 @@ jmespath==0.9.0
 jsonpatch==1.16
 jsonpointer==1.13
 jsonschema==2.6.0
-keystoneauth1==3.4.0
+keystoneauth1==3.6.2
 kombu==4.0.0
 linecache2==1.0.0
 MarkupSafe==1.0
diff --git a/openstackclient/common/versions.py b/openstackclient/common/versions.py
index 6a93d3002b..3c267bfe0a 100644
--- a/openstackclient/common/versions.py
+++ b/openstackclient/common/versions.py
@@ -14,7 +14,6 @@
 
 """Versions Action Implementation"""
 
-import os_service_types
 from osc_lib.command import command
 
 from openstackclient.i18n import _
@@ -67,7 +66,8 @@ class ShowVersions(command.Lister):
         session = self.app.client_manager.session
         version_data = session.get_all_version_data(
             interface=interface,
-            region_name=parsed_args.region_name)
+            region_name=parsed_args.region_name,
+            service_type=parsed_args.service)
 
         columns = [
             "Region Name",
@@ -83,22 +83,10 @@ class ShowVersions(command.Lister):
         if status:
             status = status.upper()
 
-        service = parsed_args.service
-        if service:
-            # Normalize service type argument to official type
-            service_type_manager = os_service_types.ServiceTypes()
-            service = service_type_manager.get_service_type(service)
-
         versions = []
         for region_name, interfaces in version_data.items():
             for interface, services in interfaces.items():
                 for service_type, service_versions in services.items():
-                    if service and service != service_type:
-                        # TODO(mordred) Once there is a version of
-                        # keystoneauth that can do this filtering
-                        # before making all the discovery calls, switch
-                        # to that.
-                        continue
                     for data in service_versions:
                         if status and status != data['status']:
                             continue
diff --git a/requirements.txt b/requirements.txt
index 205d4e64ec..78c10b4497 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,7 +6,7 @@ six>=1.10.0 # MIT
 
 Babel!=2.4.0,>=2.3.4 # BSD
 cliff!=2.9.0,>=2.8.0 # Apache-2.0
-keystoneauth1>=3.4.0 # Apache-2.0
+keystoneauth1>=3.6.2 # Apache-2.0
 openstacksdk>=0.17.0 # Apache-2.0
 osc-lib>=1.10.0 # Apache-2.0
 oslo.i18n>=3.15.3 # Apache-2.0