summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorNaveed Massjouni <naveedm9@gmail.com>2011-05-02 21:37:59 +0000
committerTarmac <>2011-05-02 21:37:59 +0000
commitc069337734e99d5833b5a1814e33ffb1fbb5fff6 (patch)
tree9532691439aa3459b4819899bae6565102d884bb /nova/api
parente4538af1a6e4b9796da3f4d7c3484084d3b72463 (diff)
parent2463fc66e363e13bf955e1ebb9b370f8e901d328 (diff)
Added support in the nova openstack api for requests with local hrefs, e.g., "imageRef":"2"
Previously, it only supported "imageRef":"http://foo.com/images/2". The 1.1 api spec defines both approaches.
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/common.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 65ed1e143..32cd689ca 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -15,6 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import re
from urlparse import urlparse
import webob
@@ -130,10 +131,16 @@ def get_image_id_from_image_hash(image_service, context, image_hash):
def get_id_from_href(href):
"""Return the id portion of a url as an int.
- Given: http://www.foo.com/bar/123?q=4
+ Given: 'http://www.foo.com/bar/123?q=4'
+ Returns: 123
+
+ In order to support local hrefs, the href argument can be just an id:
+ Given: '123'
Returns: 123
"""
+ if re.match(r'\d+$', str(href)):
+ return int(href)
try:
return int(urlparse(href).path.split('/')[-1])
except: