diff options
| author | Josh Kearney <josh@jk0.org> | 2011-08-18 15:58:12 -0500 |
|---|---|---|
| committer | Josh Kearney <josh@jk0.org> | 2011-08-18 15:58:12 -0500 |
| commit | f86a5cc4bc43923077ffe1d4098e550841f1c4f0 (patch) | |
| tree | 7788ba165a6fc4560a4433d769665c14dbff2e6e /nova/api | |
| parent | 508b45a3fda9caa92c90282045495acb6e2f638b (diff) | |
| download | nova-f86a5cc4bc43923077ffe1d4098e550841f1c4f0.tar.gz nova-f86a5cc4bc43923077ffe1d4098e550841f1c4f0.tar.xz nova-f86a5cc4bc43923077ffe1d4098e550841f1c4f0.zip | |
Review feedback.
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/contrib/rescue.py | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/nova/api/openstack/contrib/rescue.py b/nova/api/openstack/contrib/rescue.py index a30ed6dff..399bb7f35 100644 --- a/nova/api/openstack/contrib/rescue.py +++ b/nova/api/openstack/contrib/rescue.py @@ -26,39 +26,37 @@ from nova.api.openstack import faults LOG = logging.getLogger("nova.api.contrib.rescue") +def wrap_errors(fn): + """"Ensure errors are not passed along.""" + def wrapped(*args): + try: + fn(*args) + except Exception, e: + return faults.Fault(exc.HTTPInternalServerError()) + return wrapped + + class Rescue(exts.ExtensionDescriptor): """The Rescue controller for the OpenStack API.""" def __init__(self): super(Rescue, self).__init__() self.compute_api = compute.API() - def _rescue(self, input_dict, req, instance_id, exit_rescue=False): - """Rescue an instance. - - If exit_rescue is True, rescue mode should be torn down and the - instance restored to its original state. - """ + @wrap_errors + def _rescue(self, input_dict, req, instance_id): + """Rescue an instance.""" context = req.environ["nova.context"] - action = "unrescue" if exit_rescue else "rescue" - - try: - if action == "rescue": - self.compute_api.rescue(context, instance_id) - elif action == "unrescue": - self.compute_api.unrescue(context, instance_id) - except Exception, e: - LOG.exception(_("Error in %(action)s: %(e)s") % locals()) - return faults.Fault(exc.HTTPInternalServerError()) + self.compute_api.rescue(context, instance_id) return webob.Response(status_int=202) + @wrap_errors def _unrescue(self, input_dict, req, instance_id): - """Unrescue an instance. + """Rescue an instance.""" + context = req.environ["nova.context"] + self.compute_api.unrescue(context, instance_id) - We pass exit_rescue=True here so _rescue() knows we would like to exit - rescue mode. - """ - self._rescue(input_dict, req, instance_id, exit_rescue=True) + return webob.Response(status_int=202) def get_name(self): return "Rescue" |
