summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Leafe <ed@leafe.com>2011-08-02 18:23:58 +0000
committerEd Leafe <ed@leafe.com>2011-08-02 18:23:58 +0000
commit2dce2d54d14eed79ac3080e5f9ff6b715d5fc5c1 (patch)
treef2197ebe8cb10f615b84be042030d9346e20fc91
parent85795ff1f8b6a0ff3de634828208d6debd91692f (diff)
parent07d89c29389fe8f2b9f3a398ab99566d151e8e92 (diff)
Added the powerstate changes to the plugin.
-rw-r--r--nova/api/openstack/contrib/hosts.py15
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost29
2 files changed, 35 insertions, 9 deletions
diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/contrib/hosts.py
index b6a4bdb77..94fba910c 100644
--- a/nova/api/openstack/contrib/hosts.py
+++ b/nova/api/openstack/contrib/hosts.py
@@ -79,7 +79,15 @@ class HostController(object):
explanation = _("Invalid status: '%s'") % raw_val
raise webob.exc.HTTPBadRequest(explanation=explanation)
elif key == "powerstate":
- if val in ("reboot", "shutdown"):
+ if val == "startup":
+ # The only valid values for 'state' are 'reboot' or
+ # 'shutdown'. For completeness' sake there is the
+ # 'startup' option to start up a host, but this is not
+ # technically feasible now, as we run the host on the
+ # XenServer box.
+ msg = _("Host startup on XenServer is not supported."))
+ raise webob.exc.HTTPBadRequest(explanation=msg)
+ elif val in ("reboot", "shutdown"):
return self._set_powerstate(req, id, val)
else:
explanation = _("Invalid powerstate: '%s'") % raw_val
@@ -98,10 +106,9 @@ class HostController(object):
return {"host": host, "status": result}
def _set_powerstate(self, req, host, state):
- """Reboots or shuts down the host."""
+ """Reboots or shuts down the host.
+ """
context = req.environ['nova.context']
- LOG.audit(_("Changing powerstate of host %(host)s to %(state)s.")
- % locals())
result = self.compute_api.set_host_powerstate(context, host=host,
state=state)
return {"host": host, "powerstate": result}
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
index 5a5122b4a..c29d57717 100755
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
@@ -105,10 +105,20 @@ def set_host_enabled(self, arg_dict):
def _powerstate(state):
host_uuid = _get_host_uuid()
- cmd = "xe host-disable uuid=%(host_uuid)s" % locals()
- _run_command(cmd)
- cmd = "xe host-%(state)s uuid=%(host_uuid)s" % locals()
- _run_command(cmd)
+ # Host must be disabled first
+ result = _run_command("xe host-disable")
+ if result:
+ raise pluginlib.PluginError(result)
+ # All running VMs must be shutdown
+ result = _run_command("xe vm-shutdown --multiple power-state=running")
+ if result:
+ raise pluginlib.PluginError(result)
+ cmds = {"reboot": "xe host-reboot", "startup": "xe host-power-on",
+ "shutdown": "xe host-shutdown"}
+ result = _run_command(cmds[state])
+ # Should be empty string
+ if result:
+ raise pluginlib.PluginError(result)
return {"powerstate": state}
@@ -125,6 +135,14 @@ def host_shutdown(self, arg_dict):
@jsonify
+def host_start(self, arg_dict):
+ """Starts the host. NOTE: Currently not feasible, since the host
+ runs on the same machine as Xen.
+ """
+ return _powerstate("startup")
+
+
+@jsonify
def host_data(self, arg_dict):
"""Runs the commands on the xenstore host to return the current status
information.
@@ -240,4 +258,5 @@ if __name__ == "__main__":
{"host_data": host_data,
"set_host_enabled": set_host_enabled,
"host_shutdown": host_shutdown,
- "host_reboot": host_reboot})
+ "host_reboot": host_reboot,
+ "host_start": host_start})