summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEd Leafe <ed@leafe.com>2011-08-02 19:29:40 +0000
committerEd Leafe <ed@leafe.com>2011-08-02 19:29:40 +0000
commit0bd6bf4a791e03e2c1ad1715aeae3e4413705414 (patch)
tree91e9a2e6d135243126a83109f3aee68a15a7e6a0 /plugins
parent29ef7326d1daf3227e0bf31b21eba6664683955b (diff)
parentf06dee2b82bd658a57736d94974f431976085400 (diff)
Merged from lab
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost43
1 files changed, 42 insertions, 1 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
index 0cf7de0ce..5169aeb12 100755
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
@@ -103,6 +103,45 @@ def set_host_enabled(self, arg_dict):
return {"status": status}
+def _powerstate(state):
+ host_uuid = _get_host_uuid()
+ # 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}
+
+
+@jsonify
+def host_reboot(self, arg_dict):
+ """Reboots the host."""
+ return _powerstate("reboot")
+
+
+@jsonify
+def host_shutdown(self, arg_dict):
+ """Reboots the host."""
+ return _powerstate("shutdown")
+
+
+@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 set_power_state(self, arg_dict):
"""Reboots or powers off this host. Ideally, we would also like to be
@@ -245,4 +284,6 @@ if __name__ == "__main__":
XenAPIPlugin.dispatch(
{"host_data": host_data,
"set_host_enabled": set_host_enabled,
- "set_power_state": set_power_state})
+ "host_shutdown": host_shutdown,
+ "host_reboot": host_reboot,
+ "host_start": host_start})