diff --git a/lib/constants.py b/lib/constants.py index 1972303a138d24a71e9c2221751eb8b6d6e43d6d..6c3e0dd3d2db5d41cf6afbae6bb9e48a721dfc63 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -88,6 +88,7 @@ DISK_LINKS_DIR = RUN_GANETI_DIR + "/instance-disks" # daemon is started (this takes care of RUN_DIR being tmpfs) SUB_RUN_DIRS = [ RUN_GANETI_DIR, BDEV_CACHE_DIR, DISK_LINKS_DIR ] LOCK_DIR = _autoconf.LOCALSTATEDIR + "/lock" +SSCONF_LOCK_FILE = LOCK_DIR + "/ganeti-ssconf.lock" CLUSTER_CONF_FILE = DATA_DIR + "/config.data" SSL_CERT_FILE = DATA_DIR + "/server.pem" WATCHER_STATEFILE = DATA_DIR + "/watcher.data" diff --git a/lib/ssconf.py b/lib/ssconf.py index b800f25031080163f04e62f145d5af40de272014..b8189d911761f4a3503d435c50d79a81173d8f6c 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -26,7 +26,6 @@ configuration data, which is mostly static and available to all nodes. """ -import socket import sys from ganeti import errors @@ -35,6 +34,9 @@ from ganeti import utils from ganeti import serializer +SSCONF_LOCK_TIMEOUT = 10 + + class SimpleConfigReader(object): """Simple class to read configuration file. @@ -107,6 +109,40 @@ class SimpleConfigWriter(SimpleConfigReader): mode=0600) +def _SsconfPath(name): + return "%s/ssconf_%s" % (constants.DATA_DIR, name) + + +def WriteSsconfFiles(file_name): + """Writes legacy ssconf files to be used by external scripts. + + @type file_name: string + @param file_name: Path to configuration file + + """ + ssconf_lock = utils.FileLock(constants.SSCONF_LOCK_FILE) + + # Read config + cfg = SimpleConfigReader(file_name=file_name) + + # Get lock while writing files + ssconf_lock.Exclusive(blocking=True, timeout=SSCONF_LOCK_TIMEOUT) + try: + utils.WriteFile(_SsconfPath("cluster_name"), + data="%s\n" % cfg.GetClusterName()) + + utils.WriteFile(_SsconfPath("master_ip"), + data="%s\n" % cfg.GetMasterIP()) + + utils.WriteFile(_SsconfPath("master_netdev"), + data="%s\n" % cfg.GetMasterNetdev()) + + utils.WriteFile(_SsconfPath("master_node"), + data="%s\n" % cfg.GetMasterNode()) + finally: + ssconf_lock.Unlock() + + def GetMasterAndMyself(ss=None): """Get the master node and my own hostname.