|
41 | 41 |
|
42 | 42 | def make_client(instance): |
43 | 43 | """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 | + |
58 | 70 | LOG.debug('Connection: %s', conn) |
59 | 71 | LOG.debug('Network client initialized using OpenStack SDK: %s', |
60 | 72 | 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 |
66 | 73 | return conn.network |
67 | 74 |
|
68 | 75 |
|
|
0 commit comments