From f43c1f76559ae8b5b738b7ae8b69b15c379f9145 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 13 Apr 2015 16:47:49 -0500 Subject: Defer client imports So we really weren't deferring the loading of client libs dadgummit, do that for real where possible. This shaves a couple of tenths off the static import times. Also defer as much import-time procesing as possible. This is a little ugly in api.auth but this also eliminates import of the auth plugins until they are needed. Change-Id: Ia11d4b9cf98231d37449103fc29101dc17afb009 --- openstackclient/compute/client.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'openstackclient/compute') diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py index 7ca08a4f..461c3926 100644 --- a/openstackclient/compute/client.py +++ b/openstackclient/compute/client.py @@ -15,14 +15,6 @@ import logging -from novaclient import client as nova_client -from novaclient import extension - -try: - from novaclient.v2.contrib import list_extensions -except ImportError: - from novaclient.v1_1.contrib import list_extensions - from openstackclient.common import utils LOG = logging.getLogger(__name__) @@ -34,6 +26,15 @@ API_NAME = 'compute' def make_client(instance): """Returns a compute service client.""" + + # Defer client imports until we actually need them + from novaclient import client as nova_client + from novaclient import extension + try: + from novaclient.v2.contrib import list_extensions + except ImportError: + from novaclient.v1_1.contrib import list_extensions + compute_client = nova_client.get_client_class( instance._api_version[API_NAME], ) -- cgit v1.2.1