Revision 911dfc49 lib/ssconf.py
b/lib/ssconf.py | ||
---|---|---|
69 | 69 |
_MAX_SIZE = 128 * 1024 |
70 | 70 |
|
71 | 71 |
|
72 |
def ReadSsconfFile(filename): |
|
73 |
"""Reads an ssconf file and verifies its size. |
|
74 |
|
|
75 |
@type filename: string |
|
76 |
@param filename: Path to file |
|
77 |
@rtype: string |
|
78 |
@return: File contents without newlines at the end |
|
79 |
@raise RuntimeError: When the file size exceeds L{_MAX_SIZE} |
|
80 |
|
|
81 |
""" |
|
82 |
statcb = utils.FileStatHelper() |
|
83 |
|
|
84 |
data = utils.ReadFile(filename, size=_MAX_SIZE, preread=statcb) |
|
85 |
|
|
86 |
if statcb.st.st_size > _MAX_SIZE: |
|
87 |
msg = ("File '%s' has a size of %s bytes (up to %s allowed)" % |
|
88 |
(filename, statcb.st.st_size, _MAX_SIZE)) |
|
89 |
raise RuntimeError(msg) |
|
90 |
|
|
91 |
return data.rstrip("\n") |
|
92 |
|
|
93 |
|
|
72 | 94 |
class SimpleStore(object): |
73 | 95 |
"""Interface to static cluster data. |
74 | 96 |
|
... | ... | |
106 | 128 |
""" |
107 | 129 |
filename = self.KeyToFilename(key) |
108 | 130 |
try: |
109 |
data = utils.ReadFile(filename, size=_MAX_SIZE)
|
|
131 |
return ReadSsconfFile(filename)
|
|
110 | 132 |
except EnvironmentError, err: |
111 | 133 |
if err.errno == errno.ENOENT and default is not None: |
112 | 134 |
return default |
113 | 135 |
raise errors.ConfigurationError("Can't read ssconf file %s: %s" % |
114 | 136 |
(filename, str(err))) |
115 | 137 |
|
116 |
return data.rstrip("\n") |
|
117 |
|
|
118 | 138 |
def WriteFiles(self, values): |
119 | 139 |
"""Writes ssconf files used by external scripts. |
120 | 140 |
|
Also available in: Unified diff