Commit 0c223ea9 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

ganeti.ssconf: Add function to write ssconf files

This function will be used to write ssconf files from the node daemon.
By creating a lock file, we synchronize different child processes of
ganeti-noded to not overwrite each other's changes. Also, external
processes could use this lock to make sure they don't read ssconf
files while changes are going on.

The socket module is not used (anymore) in ganeti.ssconf, removing it.

Reviewed-by: iustinp
parent 54155f52
......@@ -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"
......
......@@ -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.
......
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