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
+1 -18
View File
@@ -24,7 +24,6 @@ import json
import logging
import os
from os.path import expanduser
import re
import sys
from keystoneclient.v2_0 import client as ksclient
@@ -306,21 +305,6 @@ class OpenStackImagesShell(object):
subparser.add_argument(*args, **kwargs)
subparser.set_defaults(func=callback)
# TODO(dtroyer): move this into the common client support?
# Compatibility check to remove API version as the trailing component
# in a service endpoint; also removes a trailing '/'
def _strip_version(self, 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
def _get_ksclient(self, **kwargs):
"""Get an endpoint and auth token from Keystone.
@@ -349,8 +333,7 @@ class OpenStackImagesShell(object):
endpoint_kwargs['attr'] = 'region'
endpoint_kwargs['filter_value'] = kwargs.get('region_name')
endpoint = client.service_catalog.url_for(**endpoint_kwargs)
return self._strip_version(endpoint)
return client.service_catalog.url_for(**endpoint_kwargs)
def _get_image_url(self, args):
"""Translate the available url-related options into a single string.