diff options
| author | Kevin L. Mitchell <kevin.mitchell@rackspace.com> | 2012-06-20 11:43:03 -0500 |
|---|---|---|
| committer | Kevin L. Mitchell <kevin.mitchell@rackspace.com> | 2012-06-20 15:24:26 -0500 |
| commit | 964adebb3c4ca297dd61487dffffca48283be3b5 (patch) | |
| tree | b2780c078b1c38f2f71aa09b6ffd6685f6d2fa64 /nova/api | |
| parent | cf1854946838bf14607d05acd6f347702372b744 (diff) | |
| download | nova-964adebb3c4ca297dd61487dffffca48283be3b5.tar.gz nova-964adebb3c4ca297dd61487dffffca48283be3b5.tar.xz nova-964adebb3c4ca297dd61487dffffca48283be3b5.zip | |
Admin action to reset states.
Adds an Admin API action to reset the state of an instance. This will
at least allow easy clean-up from bugs which corrupt the state of an
instance and inhibit the owner of the instance from deleting it.
Change-Id: Ia059cbd643e24e04dede06da330f444d03b07674
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/admin_actions.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/admin_actions.py b/nova/api/openstack/compute/contrib/admin_actions.py index 18adf8377..72815ed00 100644 --- a/nova/api/openstack/compute/contrib/admin_actions.py +++ b/nova/api/openstack/compute/contrib/admin_actions.py @@ -22,6 +22,7 @@ from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova import compute +from nova.compute import vm_states from nova import exception from nova import flags from nova import log as logging @@ -31,6 +32,10 @@ FLAGS = flags.FLAGS LOG = logging.getLogger(__name__) +# States usable in resetState action +state_map = dict(active=vm_states.ACTIVE, error=vm_states.ERROR) + + def authorize(context, action_name): action = 'admin_actions:%s' % action_name extensions.extension_authorizer('compute', action)(context) @@ -284,6 +289,33 @@ class AdminActionsController(wsgi.Controller): return webob.Response(status_int=202) + @wsgi.action('os-resetState') + def _reset_state(self, req, id, body): + """Permit admins to reset the state of a server.""" + context = req.environ["nova.context"] + authorize(context, 'resetState') + + # Identify the desired state from the body + try: + state = state_map[body["os-resetState"]["state"]] + except (TypeError, KeyError): + msg = _("Desired state must be specified. Valid states " + "are: %s") % ', '.join(sorted(state_map.keys())) + raise exc.HTTPBadRequest(explanation=msg) + + try: + instance = self.compute_api.get(context, id) + self.compute_api.update(context, instance, + vm_state=state, + task_state=None) + except exception.InstanceNotFound: + raise exc.HTTPNotFound(_("Server not found")) + except Exception: + readable = traceback.format_exc() + LOG.exception(_("Compute.api::resetState %s"), readable) + raise exc.HTTPUnprocessableEntity() + return webob.Response(status_int=202) + class Admin_actions(extensions.ExtensionDescriptor): """Enable admin-only server actions |
