Other particularities of the datastore:
- keys are restricted to predefined values
- values are small (<4k)
- - since the data is practically static, read keys are cached in memory
- some keys are handled specially (read from the system, so
we can't update them)
self._cfg_dir = constants.DATA_DIR
else:
self._cfg_dir = cfg_location
- self._cache = {}
def KeyToFilename(self, key):
"""Convert a given key into filename.
will be changed into ConfigurationErrors.
"""
- if key in self._cache:
- return self._cache[key]
filename = self.KeyToFilename(key)
try:
fh = file(filename, 'r')
except EnvironmentError, err:
raise errors.ConfigurationError("Can't read from the ssconf file:"
" '%s'" % str(err))
- self._cache[key] = data
return data
def GetNodeDaemonPort(self):
def SetKey(self, key, value):
"""Set the value of a key.
- This should be used only when adding a node to a cluster.
+ This should be used only when adding a node to a cluster, or in other
+ infrequent operations such as cluster-rename or master-failover.
"""
file_name = self.KeyToFilename(key)
utils.WriteFile(file_name, data="%s\n" % str(value),
uid=0, gid=0, mode=0400)
- self._cache[key] = value
def GetFileList(self):
"""Return the list of all config files.