summaryrefslogtreecommitdiff
path: root/glanceclient/common/utils.py
diff options
context:
space:
mode:
authorFlavio Percoco <flaper87@gmail.com>2014-11-24 15:12:39 +0100
committerFlavio Percoco <fpercoco@redhat.com>2014-12-09 14:45:06 +0000
commit9829d7b6b9f2232bda8039b6db54be1d8885e7a0 (patch)
tree428603b212b8f8ae3e7a3183e3ce5a7346018ce4 /glanceclient/common/utils.py
parent521cc25a0aed5c2783830847baa09344efaaf817 (diff)
downloadpython-glanceclient-9829d7b6b9f2232bda8039b6db54be1d8885e7a0.tar.gz
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
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r--glanceclient/common/utils.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index d40a704..c0d16a5 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -335,14 +335,22 @@ def get_data_file(args):
def strip_version(endpoint):
"""Strip version from the last component of endpoint if present."""
+ # NOTE(flaper87): This shouldn't be necessary if
+ # we make endpoint the first argument. However, we
+ # can't do that just yet because we need to keep
+ # backwards compatibility.
+ if not isinstance(endpoint, six.string_types):
+ raise ValueError("Expected endpoint")
+
+ version = None
# Get rid of trailing '/' if present
- if endpoint.endswith('/'):
- endpoint = endpoint[:-1]
+ endpoint = endpoint.rstrip('/')
url_bits = endpoint.split('/')
# regex to match 'v1' or 'v2.0' etc
if re.match('v\d+\.?\d*', url_bits[-1]):
+ version = float(url_bits[-1].lstrip('v'))
endpoint = '/'.join(url_bits[:-1])
- return endpoint
+ return endpoint, version
def print_image(image_obj, max_col_width=None):