These functions will be used to access config values instead of using
ssconf.
---
lib/config.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/constants.py | 1 +
lib/simpleconfig.py | 36 +++++++++++++++++++++++++++++
lib/utils.py | 23 ++++++++++++++++++
4 files changed, 123 insertions(+), 0 deletions(-)
diff --git a/lib/config.py b/lib/config.py
index 41c3052..99f26d2 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -396,6 +396,69 @@ class ConfigWriter:
del self._temporary_drbds[key]
@locking.ssynchronized(_config_lock, shared=1)
+ def GetConfigVersion(self):
+ """Get the configuration version.
+
+ @return: Config version
+
+ """
+ return self._config_data.version
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetClusterName(self):
+ """Get cluster name.
+
+ @return: Cluster name
+
+ """
+ self._OpenConfig()
+ return self._config_data.cluster.cluster_name
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetMasterNode(self):
+ """Get the hostname of the master node for this cluster.
+
+ @return: Master hostname
+
+ """
+ self._OpenConfig()
+ return self._config_data.cluster.master_node
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetMasterIP(self):
+ """Get the IP of the master node for this cluster.
+
+ @return: Master IP
+
+ """
+ self._OpenConfig()
+ return self._config_data.cluster.master_ip
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetMasterNetdev(self):
+ """Get the master network device for this cluster.
+
+ """
+ self._OpenConfig()
+ return self._config_data.cluster.master_netdev
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetFileStorageDir(self):
+ """Get the file storage dir for this cluster.
+
+ """
+ self._OpenConfig()
+ return self._config_data.cluster.file_storage_dir
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetHypervisorType(self):
+ """Get the hypervisor type for this cluster.
+
+ """
+ self._OpenConfig()
+ return self._config_data.cluster.hypervisor
+
+ @locking.ssynchronized(_config_lock, shared=1)
def GetHostKey(self):
"""Return the rsa hostkey from the config.
diff --git a/lib/constants.py b/lib/constants.py
index ba0e1d7..7dadeee 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -92,6 +92,7 @@ CLUSTER_CONF_FILE = DATA_DIR + "/config.data"
SSL_CERT_FILE = DATA_DIR + "/server.pem"
WATCHER_STATEFILE = DATA_DIR + "/watcher.data"
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
+CLUSTER_PASSWORD_FILE = DATA_DIR + "/ssconf_node_pass"
QUEUE_DIR = DATA_DIR + "/queue"
ETC_HOSTS = "/etc/hosts"
DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
diff --git a/lib/simpleconfig.py b/lib/simpleconfig.py
index 9adb29d..b8d2ee2 100644
--- a/lib/simpleconfig.py
+++ b/lib/simpleconfig.py
@@ -90,3 +90,39 @@ class SimpleConfigWriter(SimpleConfigReader):
utils.WriteFile(self._file_name,
data=serializer.Dump(self._config_data),
mode=0600)
+
+
+def GetMasterAndMyself():
+ """Get the master node and my own hostname.
+
+ This can be either used for a 'soft' check (compared to CheckMaster,
+ which exits) or just for computing both at the same time.
+
+ The function does not handle any errors, these should be handled in
+ the caller (errors.ConfigurationError, errors.ResolverError).
+
+ """
+ return SimpleConfigReader().GetMasterNode(), utils.HostInfo().name
+
+
+def CheckMaster(debug):
+ """Checks the node setup.
+
+ If this is the master, the function will return. Otherwise it will
+ exit with an exit code based on the node status.
+
+ """
+ # TODO: Move somewhere else, sys.exit() doesn't belong into a library.
+ try:
+ master_name, myself = GetMasterAndMyself()
+ except errors.ConfigurationError, err:
+ print "Cluster configuration incomplete: '%s'" % str(err)
+ sys.exit(constants.EXIT_NODESETUP_ERROR)
+ except errors.ResolverError, err:
+ sys.stderr.write("Cannot resolve my own name (%s)\n" % err.args[0])
+ sys.exit(constants.EXIT_NODESETUP_ERROR)
+
+ if myself != master_name:
+ if debug:
+ sys.stderr.write("Not master, exiting.\n")
+ sys.exit(constants.EXIT_NOTMASTER)
diff --git a/lib/utils.py b/lib/utils.py
index ebe9742..49aa51b 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1221,6 +1221,29 @@ def MergeTime(timetuple):
return float(seconds) + (float(microseconds) * 0.000001)
+def GetNodeDaemonPort():
+ """Get the node daemon port for this cluster.
+
+ Note that this routine does not read a ganeti-specific file, but
+ instead uses socket.getservbyname to allow pre-customization of
+ this parameter outside of Ganeti.
+
+ """
+ try:
+ port = socket.getservbyname("ganeti-noded", "tcp")
+ except socket.error:
+ port = constants.DEFAULT_NODED_PORT
+
+ return port
+
+
+def GetNodeDaemonPassword():
+ """Get the node password for the cluster.
+
+ """
+ return ReadFile(constants.CLUSTER_PASSWORD_FILE)
+
+
def LockedMethod(fn):
"""Synchronized object access decorator.
--
1.6.0.2