summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-21 20:52:18 +0000
committerGerrit Code Review <review@openstack.org>2012-06-21 20:52:18 +0000
commit4e3c99bc975859ab3f01aec97cf26dc522e8422d (patch)
tree4d3be69fdaf6cf2beee7f2c69cb4db9e4b27a9dd /nova/api
parentefdaeb2f16cdd96c0742afb0f776878e39fabf5b (diff)
parent964adebb3c4ca297dd61487dffffca48283be3b5 (diff)
downloadnova-4e3c99bc975859ab3f01aec97cf26dc522e8422d.tar.gz
nova-4e3c99bc975859ab3f01aec97cf26dc522e8422d.tar.xz
nova-4e3c99bc975859ab3f01aec97cf26dc522e8422d.zip
Merge "Admin action to reset states."
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/admin_actions.py32
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