Commit 03d1dba2 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Pass ssconf values from master to node

Instead of parsing the configuration on the node, we pass the ssconf
values from the master.

Reviewed-by: iustinp
parent 65c6b8e0
......@@ -501,7 +501,8 @@ class NodeHttpServer(http.HttpServer):
"""Write ssconf files.
"""
return backend.WriteSsconfFiles()
(values,) = params
return backend.WriteSsconfFiles(values)
# os -----------------------
......
......@@ -1226,8 +1226,8 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime):
return True
def WriteSsconfFiles():
ssconf.WriteSsconfFiles(constants.CLUSTER_CONF_FILE)
def WriteSsconfFiles(values):
ssconf.WriteSsconfFiles(values)
def _ErrnoOrStr(err):
......
......@@ -865,9 +865,18 @@ class ConfigWriter:
# Write ssconf files on all nodes (including locally)
if self._last_cluster_serial < self._config_data.cluster.serial_no:
if not self._offline:
rpc.RpcRunner.call_write_ssconf_files(self._UnlockedGetNodeList())
rpc.RpcRunner.call_write_ssconf_files(self._UnlockedGetNodeList(),
self._UnlockedGetSsconfValues())
self._last_cluster_serial = self._config_data.cluster.serial_no
def _UnlockedGetSsconfValues(self):
return {
"cluster_name": self._config_data.cluster.cluster_name,
"master_ip": self._config_data.cluster.master_ip,
"master_netdev": self._config_data.cluster.master_netdev,
"master_node": self._config_data.cluster.master_node,
}
@locking.ssynchronized(_config_lock)
def InitConfig(self, version, cluster_config, master_node_config):
"""Create the initial cluster configuration.
......
......@@ -622,13 +622,13 @@ class RpcRunner(object):
address_list=address_list)
@classmethod
def call_write_ssconf_files(cls, node_list):
def call_write_ssconf_files(cls, node_list, values):
"""Write ssconf files.
This is a multi-node call.
"""
return cls._StaticMultiNodeCall(node_list, "write_ssconf_files", [])
return cls._StaticMultiNodeCall(node_list, "write_ssconf_files", [values])
def call_os_diagnose(self, node_list):
"""Request a diagnose of OS definitions.
......
......@@ -27,6 +27,7 @@ configuration data, which is mostly static and available to all nodes.
"""
import sys
import re
from ganeti import errors
from ganeti import constants
......@@ -36,6 +37,8 @@ from ganeti import serializer
SSCONF_LOCK_TIMEOUT = 10
RE_VALID_SSCONF_NAME = re.compile(r'^[-_a-z0-9]+$')
class SimpleConfigReader(object):
"""Simple class to read configuration file.
......@@ -110,35 +113,28 @@ class SimpleConfigWriter(SimpleConfigReader):
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(file_name):
def WriteSsconfFiles(values):
"""Writes legacy ssconf files to be used by external scripts.
@type file_name: string
@param file_name: Path to configuration file
@type values: dict
@param values: Dictionary of (name, value)
"""
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())
for name, value in values.iteritems():
if not value.endswith("\n"):
value += "\n"
utils.WriteFile(_SsconfPath(name),
data=value)
finally:
ssconf_lock.Unlock()
......
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