Skip to content

Commit a018c6d

Browse files
Dean Troyeremonty
authored andcommitted
Rework Network client config for new SDK Connection
network.client.make_client() has always put a copy of it's SDK Connection directly into ClientManager, the new-style Connection create will move into osc-lib ClientManager, do it here too until then. Change-Id: I1edfd19c9e73320768fb9640931fafe857c980b4
1 parent 1e30be9 commit a018c6d

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

openstackclient/network/client.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,35 @@
4141

4242
def make_client(instance):
4343
"""Returns a network proxy"""
44-
if profile is None:
45-
# New SDK
46-
conn = connection.Connection(
47-
config=instance._cli_options,
48-
session=instance.session)
49-
else:
50-
prof = profile.Profile()
51-
prof.set_region(API_NAME, instance.region_name)
52-
prof.set_version(API_NAME, instance._api_version[API_NAME])
53-
prof.set_interface(API_NAME, instance.interface)
54-
conn = connection.Connection(authenticator=instance.session.auth,
55-
verify=instance.session.verify,
56-
cert=instance.session.cert,
57-
profile=prof)
44+
if getattr(instance, "sdk_connection", None) is None:
45+
if profile is None:
46+
# If the installed OpenStackSDK is new enough to not require a
47+
# Profile obejct and osc-lib is not new enough to have created
48+
# it for us, make an SDK Connection.
49+
# NOTE(dtroyer): This can be removed when this bit is in the
50+
# released osc-lib in requirements.txt.
51+
conn = connection.Connection(
52+
config=instance._cli_options,
53+
session=instance.session,
54+
)
55+
else:
56+
# Fall back to the original Connection creation
57+
prof = profile.Profile()
58+
prof.set_region(API_NAME, instance.region_name)
59+
prof.set_version(API_NAME, instance._api_version[API_NAME])
60+
prof.set_interface(API_NAME, instance.interface)
61+
conn = connection.Connection(
62+
authenticator=instance.session.auth,
63+
verify=instance.session.verify,
64+
cert=instance.session.cert,
65+
profile=prof,
66+
)
67+
68+
instance.sdk_connection = conn
69+
5870
LOG.debug('Connection: %s', conn)
5971
LOG.debug('Network client initialized using OpenStack SDK: %s',
6072
conn.network)
61-
62-
# NOTE(dtroyer): Horrible ugly hack since we don't actually save
63-
# the connection anywhere yet, so stash it in the
64-
# instance directly from here for other uses
65-
instance.sdk_connection = conn
6673
return conn.network
6774

6875

0 commit comments

Comments
 (0)