summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorStephanie Reese <reese.sm@gmail.com>2011-07-14 23:09:28 -0400
committerStephanie Reese <reese.sm@gmail.com>2011-07-14 23:09:28 -0400
commitdd78adbcf0b85f9473b5240af3366fb1dc2d4133 (patch)
tree73295640addc68faed00368a5c7fc20333be0e5d /nova/api
parentfa2cdbc5d4201ace6c1a6459bbd653b0b63b7667 (diff)
downloadnova-dd78adbcf0b85f9473b5240af3366fb1dc2d4133.tar.gz
nova-dd78adbcf0b85f9473b5240af3366fb1dc2d4133.tar.xz
nova-dd78adbcf0b85f9473b5240af3366fb1dc2d4133.zip
Fixed remove_version_from_href
Added tests
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/common.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 79969d393..8e12ce0c0 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -137,15 +137,22 @@ def get_id_from_href(href):
def remove_version_from_href(href):
- """Removes the api version from the href.
+ """Removes the first api version from the href.
Given: 'http://www.nova.com/v1.1/123'
Returns: 'http://www.nova.com/123'
+ Given: 'http://www.nova.com/v1.1'
+ Returns: 'http://www.nova.com'
+
"""
try:
- #matches /v#.#
- new_href = re.sub(r'[/][v][0-9]*.[0-9]*', '', href)
+ #removes the first instance that matches /v#.#/
+ new_href = re.sub(r'[/][v][0-9]+\.[0-9]+[/]', '/', href, count=1)
+
+ #if no version was found, try finding /v#.# at the end of the string
+ if new_href == href:
+ new_href = re.sub(r'[/][v][0-9]+\.[0-9]+$', '', href, count=1)
except:
LOG.debug(_("Error removing version from href: %s") % href)
msg = _('could not parse version from href')