Debian Codegraph @

glanceclient/client.py

raw symbols SCIP
1 # Copyright 2012 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
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 # FIXME(jamielennox): Add a deprecation warning if no session is passed.
34 # Leaving it as an option until we can ensure nothing break when we switch.
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)