diff options
| author | Ed Leafe <ed@leafe.com> | 2011-08-08 15:34:04 +0000 |
|---|---|---|
| committer | Ed Leafe <ed@leafe.com> | 2011-08-08 15:34:04 +0000 |
| commit | 6dcea0da62e881eaeb02027ea868d49c2402209d (patch) | |
| tree | d7195fb631676bc6b880a46cc85b2af6d4289543 /plugins | |
| parent | 966b7218a0fc96222e0ef0a22526f1bf3e7f2a9c (diff) | |
| parent | eb66810f6034a29724630e89739217a83b858d86 (diff) | |
| download | nova-6dcea0da62e881eaeb02027ea868d49c2402209d.tar.gz nova-6dcea0da62e881eaeb02027ea868d49c2402209d.tar.xz nova-6dcea0da62e881eaeb02027ea868d49c2402209d.zip | |
Merged trunk
Diffstat (limited to 'plugins')
| -rwxr-xr-x | plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index 873d1fe63..a28f5abfb 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -104,6 +104,7 @@ def set_host_enabled(self, arg_dict): return {"status": status} +<<<<<<< TREE def _write_config_dict(dct): conf_file = file(config_file_path, "w") json.dump(dct, conf_file) @@ -129,8 +130,14 @@ def _get_config_dict(): @jsonify def get_config(self, arg_dict): + """Return the value stored for the specified key, or None if no match.""" conf = _get_config_dict() - key = arg_dict["key"] + params = arg_dict["params"] + try: + dct = json.loads(params) + except Exception, e: + dct = params + key = dct["key"] ret = conf.get(key) if ret is None: # Can't jsonify None @@ -140,13 +147,62 @@ def get_config(self, arg_dict): @jsonify def set_config(self, arg_dict): + """Write the specified key/value pair, overwriting any existing value.""" conf = _get_config_dict() - key = arg_dict["key"] - val = arg_dict["value"] - conf.update({key: val}) + params = arg_dict["params"] + try: + dct = json.loads(params) + except Exception, e: + dct = params + key = dct["key"] + val = dct["value"] + if val is None: + # Delete the key, if present + conf.pop(key, None) + else: + conf.update({key: val}) _write_config_dict(conf) +def _power_action(action): + 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[action]) + # Should be empty string + if result: + raise pluginlib.PluginError(result) + return {"power_action": action} + + +@jsonify +def host_reboot(self, arg_dict): + """Reboots the host.""" + return _power_action("reboot") + + +@jsonify +def host_shutdown(self, arg_dict): + """Reboots the host.""" + return _power_action("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 _power_action("startup") + + @jsonify def host_data(self, arg_dict): """Runs the commands on the xenstore host to return the current status @@ -264,5 +320,8 @@ if __name__ == "__main__": XenAPIPlugin.dispatch( {"host_data": host_data, "set_host_enabled": set_host_enabled, + "host_shutdown": host_shutdown, + "host_reboot": host_reboot, + "host_start": host_start, "get_config": get_config, "set_config": set_config}) |
