Merged trunk

This commit is contained in:
Ed Leafe
2011-08-08 15:34:04 +00:00
13 changed files with 209 additions and 10 deletions
@@ -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})