From 4a8b186acb4e26ee6ea0fa4246d708411e4a772a Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 1 Oct 2008 17:33:33 +0000
Subject: [PATCH] Move functions from ssconf.py elsewhere

These functions will be used to access config values instead of using
ssconf.

Reviewed-by: iustinp
---
 lib/config.py    | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/constants.py |  1 +
 lib/utils.py     | 23 ++++++++++++++++++
 3 files changed, 87 insertions(+)

diff --git a/lib/config.py b/lib/config.py
index 5315c5bd1..403137363 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -471,6 +471,69 @@ class ConfigWriter:
       if name == instance:
         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 c5bf7d6bb..424fbb5b0 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/utils.py b/lib/utils.py
index d73ee36a0..f389bee57 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1231,6 +1231,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.
 
-- 
GitLab