From 856c67e1bdac29ee07ae066469088934f376f38c Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 1 Oct 2008 17:33:18 +0000 Subject: [PATCH] Add simple configuration reader/writer classes This will be used to read the configuration file in the node daemon. The write functionality is needed for master failover. Reviewed-by: iustinp --- lib/ssconf.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/ssconf.py b/lib/ssconf.py index fbe2fb15a..cbd26e2c8 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007 Google Inc. +# Copyright (C) 2006, 2007, 2008 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ import sys from ganeti import errors from ganeti import constants from ganeti import utils +from ganeti import serializer class SimpleStore: @@ -201,6 +202,68 @@ class WritableSimpleStore(SimpleStore): uid=0, gid=0, mode=0400) +class SimpleConfigReader: + """Simple class to read configuration file. + + """ + def __init__(self, file_name=constants.CLUSTER_CONF_FILE): + """Initializes this class. + + @type file_name: string + @param file_name: Configuration file path + + """ + self._file_name = file_name + self._config_data = serializer.Load(utils.ReadFile(file_name)) + # TODO: Error handling + + def GetClusterName(self): + return self._config_data["cluster"]["cluster_name"] + + def GetHostKey(self): + return self._config_data["cluster"]["rsahostkeypub"] + + def GetMasterNode(self): + return self._config_data["cluster"]["master_node"] + + def GetMasterIP(self): + return self._config_data["cluster"]["master_ip"] + + def GetMasterNetdev(self): + return self._config_data["cluster"]["master_netdev"] + + def GetFileStorageDir(self): + return self._config_data["cluster"]["file_storage_dir"] + + def GetHypervisorType(self): + return self._config_data["cluster"]["hypervisor"] + + def GetNodeList(self): + return self._config_data["nodes"].keys() + + +class SimpleConfigWriter(SimpleConfigReader): + """Simple class to write configuration file. + + """ + def SetMasterNode(self, node): + """Change master node. + + """ + self._config_data["cluster"]["master_node"] = node + + def Save(self): + """Writes configuration file. + + Warning: Doesn't take care of locking or synchronizing with other + processes. + + """ + utils.WriteFile(self._file_name, + data=serializer.Dump(self._config_data), + mode=0600) + + def GetMasterAndMyself(ss=None): """Get the master node and my own hostname. -- GitLab