Revision e8b5640e lib/bootstrap.py
b/lib/bootstrap.py | ||
---|---|---|
366 | 366 |
return file_storage_dir |
367 | 367 |
|
368 | 368 |
|
369 |
def _PrepareFileStorage( |
|
370 |
enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, |
|
371 |
acceptance_fn=None): |
|
372 |
"""Checks if file storage is enabled and inits the dir. |
|
369 |
def _PrepareFileBasedStorage( |
|
370 |
enabled_disk_templates, file_storage_dir, |
|
371 |
default_dir, file_disk_template, |
|
372 |
init_fn=_InitFileStorageDir, acceptance_fn=None): |
|
373 |
"""Checks if a file-base storage type is enabled and inits the dir. |
|
374 |
|
|
375 |
@type enabled_disk_templates: list of string |
|
376 |
@param enabled_disk_templates: list of enabled disk templates |
|
377 |
@type file_storage_dir: string |
|
378 |
@param file_storage_dir: the file storage directory |
|
379 |
@type default_dir: string |
|
380 |
@param default_dir: default file storage directory when C{file_storage_dir} |
|
381 |
is 'None' |
|
382 |
@type file_disk_template: string |
|
383 |
@param file_disk_template: a disk template whose storage type is 'ST_FILE' |
|
384 |
@rtype: string |
|
385 |
@returns: the name of the actual file storage directory |
|
373 | 386 |
|
374 | 387 |
""" |
388 |
assert (file_disk_template in |
|
389 |
utils.storage.GetDiskTemplatesOfStorageType(constants.ST_FILE)) |
|
375 | 390 |
if file_storage_dir is None: |
376 |
file_storage_dir = pathutils.DEFAULT_FILE_STORAGE_DIR
|
|
391 |
file_storage_dir = default_dir
|
|
377 | 392 |
if not acceptance_fn: |
378 | 393 |
acceptance_fn = \ |
379 | 394 |
lambda path: filestorage.CheckFileStoragePathAcceptance( |
... | ... | |
382 | 397 |
cluster.CheckFileStoragePathVsEnabledDiskTemplates( |
383 | 398 |
logging.warning, file_storage_dir, enabled_disk_templates) |
384 | 399 |
|
385 |
file_storage_enabled = constants.DT_FILE in enabled_disk_templates
|
|
400 |
file_storage_enabled = file_disk_template in enabled_disk_templates
|
|
386 | 401 |
if file_storage_enabled: |
387 | 402 |
try: |
388 | 403 |
acceptance_fn(file_storage_dir) |
... | ... | |
394 | 409 |
return result_file_storage_dir |
395 | 410 |
|
396 | 411 |
|
412 |
def _PrepareFileStorage( |
|
413 |
enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, |
|
414 |
acceptance_fn=None): |
|
415 |
"""Checks if file storage is enabled and inits the dir. |
|
416 |
|
|
417 |
@see: C{_PrepareFileBasedStorage} |
|
418 |
|
|
419 |
""" |
|
420 |
return _PrepareFileBasedStorage( |
|
421 |
enabled_disk_templates, file_storage_dir, |
|
422 |
pathutils.DEFAULT_FILE_STORAGE_DIR, constants.DT_FILE, |
|
423 |
init_fn=init_fn, acceptance_fn=acceptance_fn) |
|
424 |
|
|
425 |
|
|
426 |
def _PrepareSharedFileStorage( |
|
427 |
enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, |
|
428 |
acceptance_fn=None): |
|
429 |
"""Checks if shared file storage is enabled and inits the dir. |
|
430 |
|
|
431 |
@see: C{_PrepareFileBasedStorage} |
|
432 |
|
|
433 |
""" |
|
434 |
return _PrepareFileBasedStorage( |
|
435 |
enabled_disk_templates, file_storage_dir, |
|
436 |
pathutils.DEFAULT_SHARED_FILE_STORAGE_DIR, constants.DT_SHARED_FILE, |
|
437 |
init_fn=init_fn, acceptance_fn=acceptance_fn) |
|
438 |
|
|
439 |
|
|
397 | 440 |
def _InitCheckEnabledDiskTemplates(enabled_disk_templates): |
398 | 441 |
"""Checks the sanity of the enabled disk templates. |
399 | 442 |
|
... | ... | |
529 | 572 |
|
530 | 573 |
file_storage_dir = _PrepareFileStorage(enabled_disk_templates, |
531 | 574 |
file_storage_dir) |
532 |
|
|
533 |
if constants.ENABLE_SHARED_FILE_STORAGE: |
|
534 |
shared_file_storage_dir = _InitFileStorageDir(shared_file_storage_dir) |
|
535 |
else: |
|
536 |
shared_file_storage_dir = "" |
|
575 |
shared_file_storage_dir = _PrepareSharedFileStorage(enabled_disk_templates, |
|
576 |
shared_file_storage_dir) |
|
537 | 577 |
|
538 | 578 |
if not re.match("^[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}$", mac_prefix): |
539 | 579 |
raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix, |
Also available in: Unified diff