2101 |
2101 |
ssconf.SimpleStore().WriteFiles(values)
|
2102 |
2102 |
|
2103 |
2103 |
|
2104 |
|
def _ErrnoOrStr(err):
|
2105 |
|
"""Format an EnvironmentError exception.
|
2106 |
|
|
2107 |
|
If the L{err} argument has an errno attribute, it will be looked up
|
2108 |
|
and converted into a textual C{E...} description. Otherwise the
|
2109 |
|
string representation of the error will be returned.
|
2110 |
|
|
2111 |
|
@type err: L{EnvironmentError}
|
2112 |
|
@param err: the exception to format
|
2113 |
|
|
2114 |
|
"""
|
2115 |
|
if hasattr(err, "errno"):
|
2116 |
|
detail = errno.errorcode[err.errno]
|
2117 |
|
else:
|
2118 |
|
detail = str(err)
|
2119 |
|
return detail
|
2120 |
|
|
2121 |
|
|
2122 |
2104 |
def _OSOndiskAPIVersion(os_dir):
|
2123 |
2105 |
"""Compute and return the API version of a given OS.
|
2124 |
2106 |
|
... | ... | |
2138 |
2120 |
st = os.stat(api_file)
|
2139 |
2121 |
except EnvironmentError, err:
|
2140 |
2122 |
return False, ("Required file '%s' not found under path %s: %s" %
|
2141 |
|
(constants.OS_API_FILE, os_dir, _ErrnoOrStr(err)))
|
|
2123 |
(constants.OS_API_FILE, os_dir, utils.ErrnoOrStr(err)))
|
2142 |
2124 |
|
2143 |
2125 |
if not stat.S_ISREG(stat.S_IFMT(st.st_mode)):
|
2144 |
2126 |
return False, ("File '%s' in %s is not a regular file" %
|
... | ... | |
2148 |
2130 |
api_versions = utils.ReadFile(api_file).splitlines()
|
2149 |
2131 |
except EnvironmentError, err:
|
2150 |
2132 |
return False, ("Error while reading the API version file at %s: %s" %
|
2151 |
|
(api_file, _ErrnoOrStr(err)))
|
|
2133 |
(api_file, utils.ErrnoOrStr(err)))
|
2152 |
2134 |
|
2153 |
2135 |
try:
|
2154 |
2136 |
api_versions = [int(version.strip()) for version in api_versions]
|
... | ... | |
2261 |
2243 |
del os_files[filename]
|
2262 |
2244 |
continue
|
2263 |
2245 |
return False, ("File '%s' under path '%s' is missing (%s)" %
|
2264 |
|
(filename, os_dir, _ErrnoOrStr(err)))
|
|
2246 |
(filename, os_dir, utils.ErrnoOrStr(err)))
|
2265 |
2247 |
|
2266 |
2248 |
if not stat.S_ISREG(stat.S_IFMT(st.st_mode)):
|
2267 |
2249 |
return False, ("File '%s' under path '%s' is not a regular file" %
|
... | ... | |
2281 |
2263 |
# we accept missing files, but not other errors
|
2282 |
2264 |
if err.errno != errno.ENOENT:
|
2283 |
2265 |
return False, ("Error while reading the OS variants file at %s: %s" %
|
2284 |
|
(variants_file, _ErrnoOrStr(err)))
|
|
2266 |
(variants_file, utils.ErrnoOrStr(err)))
|
2285 |
2267 |
|
2286 |
2268 |
parameters = []
|
2287 |
2269 |
if constants.OS_PARAMETERS_FILE in os_files:
|
... | ... | |
2290 |
2272 |
parameters = utils.ReadFile(parameters_file).splitlines()
|
2291 |
2273 |
except EnvironmentError, err:
|
2292 |
2274 |
return False, ("Error while reading the OS parameters file at %s: %s" %
|
2293 |
|
(parameters_file, _ErrnoOrStr(err)))
|
|
2275 |
(parameters_file, utils.ErrnoOrStr(err)))
|
2294 |
2276 |
parameters = [v.split(None, 1) for v in parameters]
|
2295 |
2277 |
|
2296 |
2278 |
os_obj = objects.OS(name=name, path=os_dir,
|