diff options
| author | Naveed Massjouni <naveedm9@gmail.com> | 2011-03-17 16:02:37 -0400 |
|---|---|---|
| committer | Naveed Massjouni <naveedm9@gmail.com> | 2011-03-17 16:02:37 -0400 |
| commit | e138e0836922ee0608feefbff5e4e5d03ad14197 (patch) | |
| tree | 7f84385070b7855d4de2f637a97ef8cf3e3eb99e /nova/api | |
| parent | 1bfb97e470876f8683c559a19cd14cc3b375b1c2 (diff) | |
Now returns a 400 for a create server request with invalid hrefs for
imageRef/flavorRef values. Also added tests.
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/common.py | 12 | ||||
| -rw-r--r-- | nova/api/openstack/servers.py | 5 |
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 |
