summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEd Leafe <ed@leafe.com>2011-07-28 21:59:02 +0000
committerEd Leafe <ed@leafe.com>2011-07-28 21:59:02 +0000
commitfe195087797ca031e437c34e25380354e3ba4f56 (patch)
tree8ae12f108a8d663092b728fb6d8938fb81ebb293 /plugins
parent26fd6c3f309a2febd7538684a470d462ab83dab3 (diff)
downloadnova-fe195087797ca031e437c34e25380354e3ba4f56.tar.gz
nova-fe195087797ca031e437c34e25380354e3ba4f56.tar.xz
nova-fe195087797ca031e437c34e25380354e3ba4f56.zip
Added methods to read/write values to a config file on the XenServer host.
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost48
1 files changed, 47 insertions, 1 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
index 292bbce12..8b85fe666 100755
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
@@ -39,6 +39,7 @@ import pluginlib_nova as pluginlib
pluginlib.configure_logging("xenhost")
host_data_pattern = re.compile(r"\s*(\S+) \([^\)]+\) *: ?(.*)")
+config_file_path = "/usr/etc/xenhost.conf"
def jsonify(fnc):
@@ -103,6 +104,49 @@ def set_host_enabled(self, arg_dict):
return {"status": status}
+def _write_config_dict(dct):
+ conf_file = file(config_file_path, "w")
+ json.dump(dct, conf_file)
+ conf_file.close()
+
+
+def _get_config_dict():
+ """Returns a dict containing the key/values in the config file.
+ If the file doesn't exist, it is created, and an empty dict
+ is returned.
+ """
+ try:
+ conf_file = file(config_file_path)
+ config_dct = json.load(conf_file)
+ conf_file.close()
+ except IOError:
+ # File doesn't exist
+ config_dct = {}
+ # Create the file
+ _write_config_dict(config_dct)
+ return config_dct
+
+
+@jsonify
+def get_config(self, arg_dict):
+ conf = _get_config_dict()
+ key = arg_dict["key"]
+ ret = conf.get(key)
+ if ret is None:
+ # Can't jsonify None
+ return "None"
+ return ret
+
+
+@jsonify
+def set_config(self, arg_dict):
+ conf = _get_config_dict()
+ key = arg_dict["key"]
+ val = arg_dict["value"]
+ conf.update({key: val})
+ _write_config_dict(conf)
+
+
@jsonify
def host_data(self, arg_dict):
"""Runs the commands on the xenstore host to return the current status
@@ -217,4 +261,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,
+ "get_config": get_config,
+ "set_config": set_config})