diff options
Diffstat (limited to 'keystoneclient/discover.py')
-rw-r--r-- | keystoneclient/discover.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/keystoneclient/discover.py b/keystoneclient/discover.py index 07de97d..982683a 100644 --- a/keystoneclient/discover.py +++ b/keystoneclient/discover.py @@ -266,3 +266,34 @@ class Discover(_discover.Discover): """ version_data = self._calculate_version(version, unstable) return self._create_client(version_data, **kwargs) + + +def add_catalog_discover_hack(service_type, old, new): + """Adds a version removal rule for a particular service. + + Originally deployments of OpenStack would contain a versioned endpoint in + the catalog for different services. E.g. an identity service might look + like ``http://localhost:5000/v2.0``. This is a problem when we want to use + a different version like v3.0 as there is no way to tell where it is + located. We cannot simply change all service catalogs either so there must + be a way to handle the older style of catalog. + + This function adds a rule for a given service type that if part of the URL + matches a given regular expression in *old* then it will be replaced with + the *new* value. This will replace all instances of old with new. It should + therefore contain a regex anchor. + + For example the included rule states:: + + add_catalog_version_hack('identity', re.compile('/v2.0/?$'), '/') + + so if the catalog retrieves an *identity* URL that ends with /v2.0 or + /v2.0/ then it should replace it simply with / to fix the user's catalog. + + :param str service_type: The service type as defined in the catalog that + the rule will apply to. + :param re.RegexObject old: The regular expression to search for and replace + if found. + :param str new: The new string to replace the pattern with. + """ + _discover._VERSION_HACKS.add_discover_hack(service_type, old, new) |