Revision c9673d92
b/lib/ssconf.py | ||
---|---|---|
47 | 47 |
Other particularities of the datastore: |
48 | 48 |
- keys are restricted to predefined values |
49 | 49 |
- values are small (<4k) |
50 |
- since the data is practically static, read keys are cached in memory |
|
51 | 50 |
- some keys are handled specially (read from the system, so |
52 | 51 |
we can't update them) |
53 | 52 |
|
... | ... | |
71 | 70 |
self._cfg_dir = constants.DATA_DIR |
72 | 71 |
else: |
73 | 72 |
self._cfg_dir = cfg_location |
74 |
self._cache = {} |
|
75 | 73 |
|
76 | 74 |
def KeyToFilename(self, key): |
77 | 75 |
"""Convert a given key into filename. |
... | ... | |
91 | 89 |
will be changed into ConfigurationErrors. |
92 | 90 |
|
93 | 91 |
""" |
94 |
if key in self._cache: |
|
95 |
return self._cache[key] |
|
96 | 92 |
filename = self.KeyToFilename(key) |
97 | 93 |
try: |
98 | 94 |
fh = file(filename, 'r') |
... | ... | |
104 | 100 |
except EnvironmentError, err: |
105 | 101 |
raise errors.ConfigurationError("Can't read from the ssconf file:" |
106 | 102 |
" '%s'" % str(err)) |
107 |
self._cache[key] = data |
|
108 | 103 |
return data |
109 | 104 |
|
110 | 105 |
def GetNodeDaemonPort(self): |
... | ... | |
185 | 180 |
file_name = self.KeyToFilename(key) |
186 | 181 |
utils.WriteFile(file_name, data="%s\n" % str(value), |
187 | 182 |
uid=0, gid=0, mode=0400) |
188 |
self._cache[key] = value |
|
189 | 183 |
|
190 | 184 |
def GetFileList(self): |
191 | 185 |
"""Return the list of all config files. |
Also available in: Unified diff