Commit 89b14f05 authored by Iustin Pop's avatar Iustin Pop
Browse files

Simplify a little the ssconf update

We have (again) the KeyToFilename function, so we move the writing of
the files to a method under SimpleStore.

Reviewed-by: imsnah
parent 054596f0
......@@ -1227,7 +1227,12 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime):
def WriteSsconfFiles(values):
ssconf.WriteSsconfFiles(values)
"""Update all ssconf files.
Wrapper around the SimpleStore.WriteFiles.
"""
ssconf.SimpleStore().WriteFiles(values)
def _ErrnoOrStr(err):
......
......@@ -171,6 +171,25 @@ class SimpleStore(object):
" '%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 not value.endswith("\n"):
value += "\n"
utils.WriteFile(self.KeyToFilename(name), data=value)
finally:
ssconf_lock.Unlock()
def GetFileList(self):
"""Return the list of all config files.
......@@ -218,33 +237,6 @@ class SimpleStore(object):
return nl
def _SsconfPath(name):
if not RE_VALID_SSCONF_NAME.match(name):
raise errors.ParameterError("Invalid ssconf name: %s" % name)
return "%s/ssconf_%s" % (constants.DATA_DIR, name)
def WriteSsconfFiles(values):
"""Writes legacy ssconf files to be 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 not value.endswith("\n"):
value += "\n"
utils.WriteFile(_SsconfPath(name),
data=value)
finally:
ssconf_lock.Unlock()
def GetMasterAndMyself(ss=None):
"""Get the master node and my own hostname.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment