+ """
+ if key not in self._VALID_KEYS:
+ raise errors.ProgrammerError("Invalid key requested from SSConf: '%s'"
+ % str(key))
+
+ filename = self._cfg_dir + '/' + self._SS_FILEPREFIX + key
+ return filename
+
+ def _ReadFile(self, key):
+ """Generic routine to read keys.
+
+ This will read the file which holds the value requested. Errors
+ will be changed into ConfigurationErrors.
+
+ """
+ filename = self.KeyToFilename(key)
+ try:
+ fh = file(filename, 'r')
+ try:
+ data = fh.read(self._MAX_SIZE)
+ data = data.rstrip('\n')
+ finally:
+ fh.close()
+ except EnvironmentError, err:
+ raise errors.ConfigurationError("Can't read from the ssconf file:"
+ " '%s'" % str(err))
+ return data
+
+ def WriteFiles(self, values):
+ """Writes ssconf files used by external scripts.
+
+ @type values: dict
+ @param values: Dictionary of (name, value)
+
+ """
+ ssconf_lock = utils.FileLock(constants.SSCONF_LOCK_FILE)
+
+ # Get lock while writing files
+ ssconf_lock.Exclusive(blocking=True, timeout=SSCONF_LOCK_TIMEOUT)
+ try:
+ for name, value in values.iteritems():
+ if value and not value.endswith("\n"):
+ value += "\n"
+ utils.WriteFile(self.KeyToFilename(name), data=value, mode=0444)
+ finally:
+ ssconf_lock.Unlock()
+
+ def GetFileList(self):
+ """Return the list of all config files.
+
+ This is used for computing node replication data.
+
+ """
+ return [self.KeyToFilename(key) for key in self._VALID_KEYS]
+
+ def GetClusterName(self):
+ """Get the cluster name.
+
+ """
+ return self._ReadFile(constants.SS_CLUSTER_NAME)
+
+ def GetFileStorageDir(self):
+ """Get the file storage dir.
+
+ """
+ return self._ReadFile(constants.SS_FILE_STORAGE_DIR)
+
+ def GetMasterCandidates(self):
+ """Return the list of master candidates.
+
+ """
+ data = self._ReadFile(constants.SS_MASTER_CANDIDATES)
+ nl = data.splitlines(False)
+ return nl
+
+ def GetMasterIP(self):
+ """Get the IP of the master node for this cluster.
+
+ """
+ return self._ReadFile(constants.SS_MASTER_IP)
+
+ def GetMasterNetdev(self):
+ """Get the netdev to which we'll add the master ip.
+
+ """
+ return self._ReadFile(constants.SS_MASTER_NETDEV)
+
+ def GetMasterNode(self):
+ """Get the hostname of the master node for this cluster.
+
+ """
+ return self._ReadFile(constants.SS_MASTER_NODE)
+
+ def GetNodeList(self):
+ """Return the list of cluster nodes.
+
+ """
+ data = self._ReadFile(constants.SS_NODE_LIST)
+ nl = data.splitlines(False)
+ return nl