Don't require version to create Client instance
We currently require a version to always be passed to discover the client version that should be loaded. However, this information is commonly present in the URL instead. The current behavior forces consumers of the library to keep the required version around and/or to strip it themselves from the URL. This patch relaxes that requirement by making the version a keyword and requesting instead an endpoint to be passed. The patch gives priority to the version in the endpoint and falls back to the keyword if the later is not present. Follow-up patches will improve this code making it interact a bit more with the endpoint's catalog. Closes-bug: #1395714 Change-Id: I4ada9e724ac4709429e502b5a006604ca0453f61
This commit is contained in:
committed by
Flavio Percoco
parent
521cc25a0a
commit
9829d7b6b9
+19
-2
@@ -13,10 +13,27 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import warnings
|
||||
|
||||
from glanceclient.common import utils
|
||||
|
||||
|
||||
def Client(version, *args, **kwargs):
|
||||
def Client(version=None, endpoint=None, *args, **kwargs):
|
||||
if version is not None:
|
||||
warnings.warn(("`version` keyword is being deprecated. Please pass the"
|
||||
" version as part of the URL. "
|
||||
"http://$HOST:$PORT/v$VERSION_NUMBER"),
|
||||
DeprecationWarning)
|
||||
|
||||
endpoint, url_version = utils.strip_version(endpoint)
|
||||
|
||||
if not url_version and not version:
|
||||
msg = ("Please provide either the version or an url with the form "
|
||||
"http://$HOST:$PORT/v$VERSION_NUMBER")
|
||||
raise RuntimeError(msg)
|
||||
|
||||
version = int(version or url_version)
|
||||
|
||||
module = utils.import_versioned_module(version, 'client')
|
||||
client_class = getattr(module, 'Client')
|
||||
return client_class(*args, **kwargs)
|
||||
return client_class(endpoint, *args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user