Revision 03d1dba2 lib/ssconf.py
b/lib/ssconf.py | ||
---|---|---|
27 | 27 |
""" |
28 | 28 |
|
29 | 29 |
import sys |
30 |
import re |
|
30 | 31 |
|
31 | 32 |
from ganeti import errors |
32 | 33 |
from ganeti import constants |
... | ... | |
36 | 37 |
|
37 | 38 |
SSCONF_LOCK_TIMEOUT = 10 |
38 | 39 |
|
40 |
RE_VALID_SSCONF_NAME = re.compile(r'^[-_a-z0-9]+$') |
|
41 |
|
|
39 | 42 |
|
40 | 43 |
class SimpleConfigReader(object): |
41 | 44 |
"""Simple class to read configuration file. |
... | ... | |
110 | 113 |
|
111 | 114 |
|
112 | 115 |
def _SsconfPath(name): |
116 |
if not RE_VALID_SSCONF_NAME.match(name): |
|
117 |
raise errors.ParameterError("Invalid ssconf name: %s" % name) |
|
113 | 118 |
return "%s/ssconf_%s" % (constants.DATA_DIR, name) |
114 | 119 |
|
115 | 120 |
|
116 |
def WriteSsconfFiles(file_name):
|
|
121 |
def WriteSsconfFiles(values):
|
|
117 | 122 |
"""Writes legacy ssconf files to be used by external scripts. |
118 | 123 |
|
119 |
@type file_name: string
|
|
120 |
@param file_name: Path to configuration file
|
|
124 |
@type values: dict
|
|
125 |
@param values: Dictionary of (name, value)
|
|
121 | 126 |
|
122 | 127 |
""" |
123 | 128 |
ssconf_lock = utils.FileLock(constants.SSCONF_LOCK_FILE) |
124 | 129 |
|
125 |
# Read config |
|
126 |
cfg = SimpleConfigReader(file_name=file_name) |
|
127 |
|
|
128 | 130 |
# Get lock while writing files |
129 | 131 |
ssconf_lock.Exclusive(blocking=True, timeout=SSCONF_LOCK_TIMEOUT) |
130 | 132 |
try: |
131 |
utils.WriteFile(_SsconfPath("cluster_name"), |
|
132 |
data="%s\n" % cfg.GetClusterName()) |
|
133 |
|
|
134 |
utils.WriteFile(_SsconfPath("master_ip"), |
|
135 |
data="%s\n" % cfg.GetMasterIP()) |
|
136 |
|
|
137 |
utils.WriteFile(_SsconfPath("master_netdev"), |
|
138 |
data="%s\n" % cfg.GetMasterNetdev()) |
|
139 |
|
|
140 |
utils.WriteFile(_SsconfPath("master_node"), |
|
141 |
data="%s\n" % cfg.GetMasterNode()) |
|
133 |
for name, value in values.iteritems(): |
|
134 |
if not value.endswith("\n"): |
|
135 |
value += "\n" |
|
136 |
utils.WriteFile(_SsconfPath(name), |
|
137 |
data=value) |
|
142 | 138 |
finally: |
143 | 139 |
ssconf_lock.Unlock() |
144 | 140 |
|
Also available in: Unified diff