From 6b83e1cd31f5e138af20fbd5c118d55da092eb35 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Thu, 7 Jul 2011 15:24:12 +0000 Subject: Added API and supporting code for rebooting or shutting down XenServer hosts. --- .../xenserver/xenapi/etc/xapi.d/plugins/xenhost | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index 292bbce12..0cf7de0ce 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -103,6 +103,33 @@ def set_host_enabled(self, arg_dict): return {"status": status} +@jsonify +def set_power_state(self, arg_dict): + """Reboots or powers off this host. Ideally, we would also like to be + able to power *on* a host, but right now this is not technically + feasible. + """ + power_state = arg_dict.get("power_state") + if power_state is None: + raise pluginlib.PluginError( + _("Missing 'power_state' argument to set_power_state")) + # 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", "on": "xe host-power-on", +# "off": "xe host-shutdown"} +# result = _run_command(cmds[power_state]) +# # Should be empty string +# if result: +# raise pluginlib.PluginError(result) + return {"power_state": power_state} + + @jsonify def host_data(self, arg_dict): """Runs the commands on the xenstore host to return the current status @@ -217,4 +244,5 @@ def cleanup(dct): if __name__ == "__main__": XenAPIPlugin.dispatch( {"host_data": host_data, - "set_host_enabled": set_host_enabled}) + "set_host_enabled": set_host_enabled, + "set_power_state": set_power_state}) -- cgit From 85795ff1f8b6a0ff3de634828208d6debd91692f Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Mon, 1 Aug 2011 21:06:47 +0000 Subject: Added option for rebooting or shutting down a host. --- .../xenserver/xenapi/etc/xapi.d/plugins/xenhost | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index 292bbce12..5a5122b4a 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -103,6 +103,27 @@ def set_host_enabled(self, arg_dict): return {"status": status} +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) + 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_data(self, arg_dict): """Runs the commands on the xenstore host to return the current status @@ -217,4 +238,6 @@ def cleanup(dct): if __name__ == "__main__": XenAPIPlugin.dispatch( {"host_data": host_data, - "set_host_enabled": set_host_enabled}) + "set_host_enabled": set_host_enabled, + "host_shutdown": host_shutdown, + "host_reboot": host_reboot}) -- cgit From 07d89c29389fe8f2b9f3a398ab99566d151e8e92 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Tue, 2 Aug 2011 02:19:31 +0000 Subject: Added host shutdown/reboot conditioning. --- .../xenserver/xenapi/etc/xapi.d/plugins/xenhost | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index 5a5122b4a..873b4c58d 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} @@ -124,6 +134,12 @@ def host_shutdown(self, arg_dict): return _powerstate("shutdown") +@jsonify +def host_start(self, arg_dict): + """Starts the host.""" + return _powerstate("startup") + + @jsonify def host_data(self, arg_dict): """Runs the commands on the xenstore host to return the current status @@ -240,4 +256,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}) -- cgit From a0ec6a6aa5ebdde1d099c5f6c03cf1dbd28441fa Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Wed, 3 Aug 2011 00:52:15 +0000 Subject: Removed duplicate methods created by previous merge. --- .../xenserver/xenapi/etc/xapi.d/plugins/xenhost | 27 ---------------------- 1 file changed, 27 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index 5169aeb12..c29d57717 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -142,33 +142,6 @@ def host_start(self, arg_dict): return _powerstate("startup") -@jsonify -def set_power_state(self, arg_dict): - """Reboots or powers off this host. Ideally, we would also like to be - able to power *on* a host, but right now this is not technically - feasible. - """ - power_state = arg_dict.get("power_state") - if power_state is None: - raise pluginlib.PluginError( - _("Missing 'power_state' argument to set_power_state")) - # 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", "on": "xe host-power-on", -# "off": "xe host-shutdown"} -# result = _run_command(cmds[power_state]) -# # Should be empty string -# if result: -# raise pluginlib.PluginError(result) - return {"power_state": power_state} - - @jsonify def host_data(self, arg_dict): """Runs the commands on the xenstore host to return the current status -- cgit From 75b110aa451382cce94f10a392597b40df97839c Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Thu, 4 Aug 2011 20:49:21 +0000 Subject: Changed all references to 'power state' to 'power action' as requested by review. --- plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index c29d57717..f6a9ac8d8 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -103,7 +103,7 @@ def set_host_enabled(self, arg_dict): return {"status": status} -def _powerstate(state): +def _power_action(action): host_uuid = _get_host_uuid() # Host must be disabled first result = _run_command("xe host-disable") @@ -115,23 +115,23 @@ def _powerstate(state): raise pluginlib.PluginError(result) cmds = {"reboot": "xe host-reboot", "startup": "xe host-power-on", "shutdown": "xe host-shutdown"} - result = _run_command(cmds[state]) + result = _run_command(cmds[action]) # Should be empty string if result: raise pluginlib.PluginError(result) - return {"powerstate": state} + return {"power_action": action} @jsonify def host_reboot(self, arg_dict): """Reboots the host.""" - return _powerstate("reboot") + return _power_action("reboot") @jsonify def host_shutdown(self, arg_dict): """Reboots the host.""" - return _powerstate("shutdown") + return _power_action("shutdown") @jsonify @@ -139,7 +139,7 @@ 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") + return _power_action("startup") @jsonify -- cgit