summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEd Leafe <ed@leafe.com>2011-08-04 19:32:10 +0000
committerEd Leafe <ed@leafe.com>2011-08-04 19:32:10 +0000
commit6ff2d660d777087b1a83550e81b1df24aea8f7a5 (patch)
treec5dda46199800ffde7f2f25651fc5df91af79d76 /plugins
parent3f7c71fd38a67e6983de0bb268e5c65abc5753f4 (diff)
parent7b69ef4fe1e4aabcf44789455b96492b168ad6f5 (diff)
downloadnova-6ff2d660d777087b1a83550e81b1df24aea8f7a5.tar.gz
nova-6ff2d660d777087b1a83550e81b1df24aea8f7a5.tar.xz
nova-6ff2d660d777087b1a83550e81b1df24aea8f7a5.zip
Added xenhost config get/setting.
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost66
1 files changed, 62 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..b48a303ee 100755
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
@@ -129,8 +129,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 +146,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 _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 host_data(self, arg_dict):
"""Runs the commands on the xenstore host to return the current status
@@ -264,5 +319,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})