diff options
author | Jamie Lennox <jamielennox@redhat.com> | 2014-10-21 17:18:40 +0200 |
---|---|---|
committer | Jamie Lennox <jamielennox@redhat.com> | 2014-12-10 06:15:47 +0000 |
commit | ff1c0e1347ddb3f07103c238b642f78780f80022 (patch) | |
tree | 0d9ac6dc97016438b6a3b46cc9f91d5f9a340bb1 /keystoneclient/discover.py | |
parent | f8f81bb119b63b85f9a3f72ba81045e065b01cce (diff) | |
download | python-keystoneclient-ff1c0e1347ddb3f07103c238b642f78780f80022.tar.gz |
Expose version matching functions to the public
The functions to match a version or convert a string version number into
a tuple have shown to be useful in at least auth_token middleware. I
think this is also better as _discover should really only be a shadow
for the discover file because of the circular dependency problems.
_discover shouldn't really need to be used even within client.
Closes-Bug: #1400998
Change-Id: Icf700c30d01e0700e437437a23e63a7f100ce4d3
Diffstat (limited to 'keystoneclient/discover.py')
-rw-r--r-- | keystoneclient/discover.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/keystoneclient/discover.py b/keystoneclient/discover.py index 695d345..51692ca 100644 --- a/keystoneclient/discover.py +++ b/keystoneclient/discover.py @@ -30,6 +30,46 @@ _CLIENT_VERSIONS = {2: v2_client.Client, 3: v3_client.Client} +# functions needed from the private file that can be made public + +def normalize_version_number(version): + """Turn a version representation into a tuple. + + Takes a string, tuple or float which represent version formats we can + handle and converts them into a (major, minor) version tuple that we can + actually use for discovery. + + e.g. 'v3.3' gives (3, 3) + 3.1 gives (3, 1) + + :param version: Inputted version number to try and convert. + + :returns: A usable version tuple + :rtype: tuple + + :raises TypeError: if the inputted version cannot be converted to tuple. + """ + return _discover.normalize_version_number(version) + + +def version_match(required, candidate): + """Test that an available version is a suitable match for a required + version. + + To be suitable a version must be of the same major version as required + and be at least a match in minor/patch level. + + eg. 3.3 is a match for a required 3.1 but 4.1 is not. + + :param tuple required: the version that must be met. + :param tuple candidate: the version to test against required. + + :returns: True if candidate is suitable False otherwise. + :rtype: bool + """ + return _discover.version_match(required, candidate) + + def available_versions(url, session=None, **kwargs): """Retrieve raw version data from a url.""" if not session: |