| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
import warnings |
| 17 |
|
| 18 |
from oslo_utils import importutils |
| 19 |
|
| 20 |
from glanceclient.common import utils |
| 21 |
|
| 22 |
|
| 23 |
def Client(version=None, endpoint=None, session=None, *args, **kwargs): |
| 24 |
"""Client for the OpenStack Images API. |
| 25 |
|
| 26 |
Generic client for the OpenStack Images API. See version classes |
| 27 |
for specific details. |
| 28 |
|
| 29 |
:param string version: The version of API to use. |
| 30 |
:param session: A keystoneauth1 session that should be used for transport. |
| 31 |
:type session: keystoneauth1.session.Session |
| 32 |
""" |
| 33 |
|
| 34 |
|
| 35 |
if session: |
| 36 |
if endpoint: |
| 37 |
kwargs.setdefault('endpoint_override', endpoint) |
| 38 |
|
| 39 |
if not version: |
| 40 |
__, version = utils.strip_version(endpoint) |
| 41 |
|
| 42 |
if not version: |
| 43 |
msg = ("You must provide a client version when using session") |
| 44 |
raise RuntimeError(msg) |
| 45 |
|
| 46 |
else: |
| 47 |
if version is not None: |
| 48 |
warnings.warn(("`version` keyword is being deprecated. Please pass" |
| 49 |
" the version as part of the URL. " |
| 50 |
"http://$HOST:$PORT/v$VERSION_NUMBER"), |
| 51 |
DeprecationWarning) |
| 52 |
|
| 53 |
endpoint, url_version = utils.strip_version(endpoint) |
| 54 |
version = version or url_version |
| 55 |
|
| 56 |
if not version: |
| 57 |
msg = ("Please provide either the version or an url with the form " |
| 58 |
"http://$HOST:$PORT/v$VERSION_NUMBER") |
| 59 |
raise RuntimeError(msg) |
| 60 |
|
| 61 |
module = importutils.import_versioned_module('glanceclient', int(version), |
| 62 |
'client') |
| 63 |
client_class = getattr(module, 'Client') |
| 64 |
return client_class(endpoint, *args, session=session, **kwargs) |