Handle endpoints with versions consistently

When using the cli the Glance client wraps the endpoint in a 'strip
version' function. This means that endpoints of the following forms can
both be used:

https://region-x.images.example.com:443/v1
https://region-x.images.example.com:443

When calling the client library directly (as Ceilometer does) however
only endpoints of the second form work. The cli and library should handle
the two cases consistently.

Addresses bug 1243276.

Change-Id: Ice7b581fee32540a7057ba47433a10166a3caed2
This commit is contained in:
Stuart McLaren
2013-10-22 15:51:49 +00:00
parent f6c3d4e141
commit ee7fd2f5bd
6 changed files with 102 additions and 22 deletions
+13
View File
@@ -17,6 +17,7 @@ from __future__ import print_function
import errno
import os
import re
import sys
import uuid
@@ -315,3 +316,15 @@ def get_data_file(args):
else:
# (3) no image data provided
return None
def strip_version(endpoint):
"""Strip version from the last component of endpoint if present."""
# Get rid of trailing '/' if present
if endpoint.endswith('/'):
endpoint = endpoint[:-1]
url_bits = endpoint.split('/')
# regex to match 'v1' or 'v2.0' etc
if re.match('v\d+\.?\d*', url_bits[-1]):
endpoint = '/'.join(url_bits[:-1])
return endpoint