From fe195087797ca031e437c34e25380354e3ba4f56 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Thu, 28 Jul 2011 21:59:02 +0000 Subject: Added methods to read/write values to a config file on the XenServer host. --- .../xenserver/xenapi/etc/xapi.d/plugins/xenhost | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) 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}) -- cgit From 1753da4d586f896f449828879e4361241289e376 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Thu, 28 Jul 2011 22:25:08 +0000 Subject: Added the config values to the return of the host_data method. --- plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index 8b85fe666..873d1fe63 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -159,6 +159,8 @@ def host_data(self, arg_dict): # We have the raw dict of values. Extract those that we need, # and convert the data types as needed. ret_dict = cleanup(parsed_data) + # Add any config settings + ret_dict.update(_get_config_dict) return ret_dict -- cgit From b5ff9bc2add98444773a26ce37e1ceb82e9531ae Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Thu, 4 Aug 2011 21:10:22 +0000 Subject: Removed test show() method --- nova/api/openstack/contrib/hosts.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/contrib/hosts.py index ddb611905..7290360ad 100644 --- a/nova/api/openstack/contrib/hosts.py +++ b/nova/api/openstack/contrib/hosts.py @@ -65,13 +65,6 @@ class HostController(object): def index(self, req): return {'hosts': _list_hosts(req)} - def show(self, req, id): - """Check the query vars for values to be returned from the host config - settings. Return a dict with the query var as the key and the config - setting as the value. - """ - return {"PARAMS": req.params.keys()} - @check_host def update(self, req, id, body): for raw_key, raw_val in body.iteritems(): -- cgit From de23e5ad63f6293060835e496363c935044480d6 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Mon, 8 Aug 2011 20:03:14 +0000 Subject: cleaned up unneeded line --- plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index a28f5abfb..4028fdc7a 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -104,7 +104,6 @@ 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) -- cgit From 3f23c79bbb556cf05f7cf8c839edb6398464e051 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Mon, 8 Aug 2011 20:12:35 +0000 Subject: Cleaned up merge messes. --- nova/api/openstack/contrib/hosts.py | 15 +-------------- nova/compute/api.py | 5 ----- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/contrib/hosts.py index 63e5f545f..ecaa365b7 100644 --- a/nova/api/openstack/contrib/hosts.py +++ b/nova/api/openstack/contrib/hosts.py @@ -79,20 +79,6 @@ class HostController(object): else: explanation = _("Invalid status: '%s'") % raw_val raise webob.exc.HTTPBadRequest(explanation=explanation) - elif key == "power_state": - if val == "startup": - # The only valid values for 'state' are 'reboot' or - # 'shutdown'. For completeness' sake there is the - # 'startup' option to start up a host, but this is not - # technically feasible now, as we run the host on the - # XenServer box. - msg = _("Host startup on XenServer is not supported.") - raise webob.exc.HTTPBadRequest(explanation=msg) - elif val in ("reboot", "shutdown"): - return self._set_powerstate(req, id, val) - else: - explanation = _("Invalid powerstate: '%s'") % raw_val - raise webob.exc.HTTPBadRequest(explanation=explanation) else: explanation = _("Invalid update setting: '%s'") % raw_key raise webob.exc.HTTPBadRequest(explanation=explanation) @@ -117,6 +103,7 @@ class HostController(object): action=action) except NotImplementedError as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) + return {"host": host, "power_action": result} def startup(self, req, id): return self._host_power_action(req, host=id, action="startup") diff --git a/nova/compute/api.py b/nova/compute/api.py index ccff421fe..d2c08678b 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1004,11 +1004,6 @@ class API(base.Base): return self._call_compute_message("host_power_action", context, host=host, params={"action": action}) - def host_power_action(self, context, host, action): - """Reboots or shuts down the host.""" - return self._call_compute_message("host_power_action", context, - instance_id=None, host=host, params={"action": action}) - @scheduler_api.reroute_compute("diagnostics") def get_diagnostics(self, context, instance_id): """Retrieve diagnostics for the given instance.""" -- cgit From fee2812193258a1a4ade3116282d3f5c1cf1f58c Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Mon, 8 Aug 2011 21:46:33 +0000 Subject: Fixed typo found in review --- plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost index 8bd376264..cd9694ce1 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost @@ -215,7 +215,8 @@ def host_data(self, arg_dict): # and convert the data types as needed. ret_dict = cleanup(parsed_data) # Add any config settings - ret_dict.update(_get_config_dict) + config = _get_config_dict() + ret_dict.update(config) return ret_dict -- cgit