summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/contrib/hosts.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/contrib/hosts.py
index 55e57e1a4..cc71cadbd 100644
--- a/nova/api/openstack/contrib/hosts.py
+++ b/nova/api/openstack/contrib/hosts.py
@@ -78,6 +78,12 @@ class HostController(object):
else:
explanation = _("Invalid status: '%s'") % raw_val
raise webob.exc.HTTPBadRequest(explanation=explanation)
+ elif key == "power_state":
+ if val in ("reboot", "off", "on"):
+ return self._set_power_state(req, id, val)
+ else:
+ explanation = _("Invalid status: '%s'") % raw_val
+ raise webob.exc.HTTPBadRequest(explanation=explanation)
else:
explanation = _("Invalid update setting: '%s'") % raw_key
raise webob.exc.HTTPBadRequest(explanation=explanation)
@@ -89,8 +95,28 @@ class HostController(object):
LOG.audit(_("Setting host %(host)s to %(state)s.") % locals())
result = self.compute_api.set_host_enabled(context, host=host,
enabled=enabled)
+ if result not in ("enabled", "disabled"):
+ # An error message was returned
+ raise webob.exc.HTTPBadRequest(explanation=result)
return {"host": host, "status": result}
+ def _set_power_state(self, req, host, power_state):
+ """Turns the specified host on/off, or reboots the host."""
+ context = req.environ['nova.context']
+ if power_state == "on":
+ raise webob.exc.HTTPNotImplemented()
+ if power_state == "reboot":
+ msg = _("Rebooting host %(host)s")
+ else:
+ msg = _("Powering off host %(host)s.")
+ LOG.audit(msg % locals())
+ result = self.compute_api.set_power_state(context, host=host,
+ power_state=power_state)
+ if result != power_state:
+ # An error message was returned
+ raise webob.exc.HTTPBadRequest(explanation=result)
+ return {"host": host, "power_state": result}
+
class Hosts(extensions.ExtensionDescriptor):
def get_name(self):