summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/common.py12
-rw-r--r--nova/api/openstack/servers.py5
2 files changed, 12 insertions, 5 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 74ac21024..b224cbfb4 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -15,9 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
-import webob.exc
-
+import re
from nova import exception
+from webob import exc
+import webob.exc
def limited(items, request, max_limit=1000):
@@ -74,3 +75,10 @@ def get_image_id_from_image_hash(image_service, context, image_hash):
if abs(hash(image_id)) == int(image_hash):
return image_id
raise exception.NotFound(image_hash)
+
+
+def get_id_from_href(href):
+ m = re.match(r'http.+/.+/(\d)+$', href)
+ if not m:
+ raise exc.HTTPBadRequest(_('could not parse id from href'))
+ return int(m.group(1))
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index f03225b55..6f25d10bd 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -512,7 +512,6 @@ class Controller(wsgi.Controller):
return kernel_id, ramdisk_id
-
class ControllerV10(Controller):
def _image_id_from_req_data(self, data):
return data['server']['imageId']
@@ -532,11 +531,11 @@ class ControllerV10(Controller):
class ControllerV11(Controller):
def _image_id_from_req_data(self, data):
href = data['server']['imageRef']
- return href.split('/')[-1]
+ return common.get_id_from_href(href)
def _flavor_id_from_req_data(self, data):
href = data['server']['flavorRef']
- return href.split('/')[-1]
+ return common.get_id_from_href(href)
def _get_view_builder(self, req):
base_url = req.application_url