diff options
| author | Stephanie Reese <reese.sm@gmail.com> | 2011-07-14 23:09:28 -0400 |
|---|---|---|
| committer | Stephanie Reese <reese.sm@gmail.com> | 2011-07-14 23:09:28 -0400 |
| commit | dd78adbcf0b85f9473b5240af3366fb1dc2d4133 (patch) | |
| tree | 73295640addc68faed00368a5c7fc20333be0e5d /nova/api | |
| parent | fa2cdbc5d4201ace6c1a6459bbd653b0b63b7667 (diff) | |
| download | nova-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.py | 13 |
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') |
