24
24
from nova.api.openstack import common
25
25
from nova.api.openstack import extensions
26
26
from nova.api.openstack import faults
27
from nova.api.openstack.contrib import admin_only
27
28
from nova.scheduler import api as scheduler_api
70
71
key = raw_key.lower().strip()
71
72
val = raw_val.lower().strip()
72
73
# NOTE: (dabo) Right now only 'status' can be set, but other
74
# settings may follow.
74
75
if key == "status":
75
76
if val[:6] in ("enable", "disabl"):
76
77
return self._set_enabled_status(req, id,
89
90
LOG.audit(_("Setting host %(host)s to %(state)s.") % locals())
90
91
result = self.compute_api.set_host_enabled(context, host=host,
93
if result not in ("enabled", "disabled"):
94
# An error message was returned
95
raise webob.exc.HTTPBadRequest(explanation=result)
92
96
return {"host": host, "status": result}
98
def _host_power_action(self, req, host, action):
99
"""Reboots, shuts down or powers up the host."""
100
context = req.environ['nova.context']
102
result = self.compute_api.host_power_action(context, host=host,
104
except NotImplementedError as e:
105
raise webob.exc.HTTPBadRequest(explanation=e.msg)
106
return {"host": host, "power_action": result}
108
def startup(self, req, id):
109
return self._host_power_action(req, host=id, action="startup")
111
def shutdown(self, req, id):
112
return self._host_power_action(req, host=id, action="shutdown")
114
def reboot(self, req, id):
115
return self._host_power_action(req, host=id, action="reboot")
95
118
class Hosts(extensions.ExtensionDescriptor):
96
119
def get_name(self):
108
131
def get_updated(self):
109
132
return "2011-06-29T00:00:00+00:00"
134
@admin_only.admin_only
111
135
def get_resources(self):
112
resources = [extensions.ResourceExtension('os-hosts', HostController(),
113
collection_actions={'update': 'PUT'}, member_actions={})]
136
resources = [extensions.ResourceExtension('os-hosts',
137
HostController(), collection_actions={'update': 'PUT'},
138
member_actions={"startup": "GET", "shutdown": "GET",