From 942f0404a3d7052830cdc52c17c85de7cd3bc0da Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Wed, 18 Jan 2012 19:31:01 +0000 Subject: Validating image id for rebuild. bug: 886701 Change-Id: I20ad03edca390af9203569e02ae0c1af5bb7beaf --- nova/compute/api.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index 012217584..3b4cfdeaf 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1255,6 +1255,12 @@ class API(base.Base): instance['uuid'], params={'reboot_type': reboot_type}) + def _validate_image_href(self, context, image_href): + """Throws an ImageNotFound exception if image_href does not exist.""" + (image_service, image_id) = nova.image.get_image_service(context, + image_href) + image_service.show(context, image_id) + @wrap_check_policy @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF], task_state=[None, task_states.RESIZE_VERIFY]) @@ -1262,6 +1268,8 @@ class API(base.Base): def rebuild(self, context, instance, image_href, admin_password, **kwargs): """Rebuild the given instance with the provided attributes.""" + self._validate_image_href(context, image_href) + files_to_inject = kwargs.pop('files_to_inject', []) self._check_injected_file_quota(context, files_to_inject) -- cgit