From 574166045c6d4b7d8f5e2afeaa6d13aabf03bdb0 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 10 Nov 2011 17:15:28 -0500 Subject: Converting rescue/unrescue to use instance objects Related to blueprint internal-uuids Change-Id: If256d9a1251e780ff044bd87e0805c9f511c05e9 --- nova/api/openstack/contrib/rescue.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/rescue.py b/nova/api/openstack/contrib/rescue.py index 4e1beb0ba..d3f38b200 100644 --- a/nova/api/openstack/contrib/rescue.py +++ b/nova/api/openstack/contrib/rescue.py @@ -17,12 +17,13 @@ import webob from webob import exc +from nova.api.openstack import extensions as exts +from nova.api.openstack import faults from nova import compute +from nova import exception from nova import flags from nova import log as logging from nova import utils -from nova.api.openstack import extensions as exts -from nova.api.openstack import faults FLAGS = flags.FLAGS @@ -41,24 +42,33 @@ class Rescue(exts.ExtensionDescriptor): super(Rescue, self).__init__(ext_mgr) self.compute_api = compute.API() + def _get_instance(self, context, instance_id): + try: + return self.compute_api.get(context, instance_id) + except exception.InstanceNotFound: + msg = _("Server not found") + raise exc.HTTPNotFound(msg) + @exts.wrap_errors def _rescue(self, input_dict, req, instance_id): """Rescue an instance.""" context = req.environ["nova.context"] + if input_dict['rescue'] and 'adminPass' in input_dict['rescue']: password = input_dict['rescue']['adminPass'] else: password = utils.generate_password(FLAGS.password_length) - self.compute_api.rescue(context, instance_id, rescue_password=password) + instance = self._get_instance(context, instance_id) + self.compute_api.rescue(context, instance, rescue_password=password) return {'adminPass': password} @exts.wrap_errors def _unrescue(self, input_dict, req, instance_id): """Unrescue an instance.""" context = req.environ["nova.context"] - self.compute_api.unrescue(context, instance_id) - + instance = self._get_instance(context, instance_id) + self.compute_api.unrescue(context, instance) return webob.Response(status_int=202) def get_actions(self): -- cgit