This will be used to read the configuration file in the node daemon.
The write functionality is needed for master failover.
---
Makefile.am | 1 +
lib/simpleconfig.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 0 deletions(-)
create mode 100644 lib/simpleconfig.py
diff --git a/Makefile.am b/Makefile.am
index c329c5e..afce430 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -78,6 +78,7 @@ pkgpython_PYTHON = \
lib/opcodes.py \
lib/rpc.py \
lib/serializer.py \
+ lib/simpleconfig.py \
lib/ssconf.py \
lib/ssh.py \
lib/utils.py \
diff --git a/lib/simpleconfig.py b/lib/simpleconfig.py
new file mode 100644
index 0000000..9adb29d
--- /dev/null
+++ b/lib/simpleconfig.py
@@ -0,0 +1,92 @@
+#
+#
+
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+
+"""Simple configuration reader"""
+
+
+import os
+
+from ganeti import constants
+from ganeti import errors
+from ganeti import serializer
+from ganeti import utils
+
+
+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)
--
1.6.0.2