From f600c0eafbf9aff23b6efa1c7b94797a25873b99 Mon Sep 17 00:00:00 2001
From: wanghong <w.wanghong@huawei.com>
Date: Mon, 20 Oct 2014 15:29:53 +0800
Subject: [PATCH] only generate one clientmanager instance in interactive mode

Currently, we repeated to generate clientmanager instance when run
command in interactive mode. This should be avoided.

Change-Id: I0536a690bc173be38af08a2e4443115532041efd
Closes-Bug: #1383083
---
 openstackclient/shell.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/openstackclient/shell.py b/openstackclient/shell.py
index 1f9eb32b53..668e48b5fc 100644
--- a/openstackclient/shell.py
+++ b/openstackclient/shell.py
@@ -68,6 +68,8 @@ class OpenStackShell(app.App):
         # Assume TLS host certificate verification is enabled
         self.verify = True
 
+        self.client_manager = None
+
         # NOTE(dtroyer): This hack changes the help action that Cliff
         #                automatically adds to the parser so we can defer
         #                its execution until after the api-versioned commands
@@ -204,8 +206,12 @@ class OpenStackShell(app.App):
 
         return clientmanager.build_plugin_option_parser(parser)
 
-    def authenticate_user(self):
-        """Verify the required authentication credentials are present"""
+    def initialize_clientmanager(self):
+        """Validating authentication options and generate a clientmanager"""
+
+        if self.client_manager:
+            self.log.debug('The clientmanager has been initialized already')
+            return
 
         self.log.debug("validating authentication options")
 
@@ -370,11 +376,11 @@ class OpenStackShell(app.App):
             return
         if cmd.best_effort:
             try:
-                self.authenticate_user()
+                self.initialize_clientmanager()
             except Exception:
                 pass
         else:
-            self.authenticate_user()
+            self.initialize_clientmanager()
         return
 
     def clean_up(self, cmd, result, err):
@@ -409,7 +415,7 @@ class OpenStackShell(app.App):
     def interact(self):
         # NOTE(dtroyer): Maintain the old behaviour for interactive use as
         #                this path does not call prepare_to_run_command()
-        self.authenticate_user()
+        self.initialize_clientmanager()
         super(OpenStackShell, self).interact()