Revision 7dd999fc lib/ssconf.py
b/lib/ssconf.py | ||
---|---|---|
29 | 29 |
import sys |
30 | 30 |
import re |
31 | 31 |
import os |
32 |
import errno |
|
32 | 33 |
|
33 | 34 |
from ganeti import errors |
34 | 35 |
from ganeti import constants |
... | ... | |
307 | 308 |
filename = self._cfg_dir + '/' + self._SS_FILEPREFIX + key |
308 | 309 |
return filename |
309 | 310 |
|
310 |
def _ReadFile(self, key): |
|
311 |
def _ReadFile(self, key, default=None):
|
|
311 | 312 |
"""Generic routine to read keys. |
312 | 313 |
|
313 | 314 |
This will read the file which holds the value requested. Errors |
... | ... | |
318 | 319 |
try: |
319 | 320 |
data = utils.ReadFile(filename, size=self._MAX_SIZE) |
320 | 321 |
except EnvironmentError, err: |
322 |
if err.errno == errno.ENOENT and default is not None: |
|
323 |
return default |
|
321 | 324 |
raise errors.ConfigurationError("Can't read from the ssconf file:" |
322 | 325 |
" '%s'" % str(err)) |
323 | 326 |
data = data.rstrip('\n') |
... | ... | |
466 | 469 |
|
467 | 470 |
""" |
468 | 471 |
try: |
469 |
return int(self._ReadFile(constants.SS_PRIMARY_IP_FAMILY)) |
|
472 |
return int(self._ReadFile(constants.SS_PRIMARY_IP_FAMILY, |
|
473 |
default=netutils.IP4Address.family)) |
|
470 | 474 |
except (ValueError, TypeError), err: |
471 | 475 |
raise errors.ConfigurationError("Error while trying to parse primary ip" |
472 | 476 |
" family: %s" % err) |
Also available in: Unified diff