Revision 3039e2dc lib/bootstrap.py

b/lib/bootstrap.py
30 30
import time
31 31
import tempfile
32 32

  
33
from ganeti.cmdlib import cluster
33 34
from ganeti import rpc
34 35
from ganeti import ssh
35 36
from ganeti import utils
......
41 42
from ganeti import serializer
42 43
from ganeti import hypervisor
43 44
from ganeti.storage import drbd
45
from ganeti.storage import filestorage
44 46
from ganeti import netutils
45 47
from ganeti import luxi
46 48
from ganeti import jstore
......
334 336
  _WaitForSshDaemon(node, netutils.GetDaemonPort(constants.SSH), family)
335 337

  
336 338

  
337
def _PrepareFileStorage(enabled_disk_templates, file_storage_dir):
338
  """Checks if file storage is enabled and inits the dir.
339

  
340
  """
341
  if utils.storage.IsFileStorageEnabled(enabled_disk_templates):
342
    file_storage_dir = _InitFileStorageDir(file_storage_dir)
343
  else:
344
    file_storage_dir = ""
345
  return file_storage_dir
346

  
347

  
348 339
def _InitFileStorageDir(file_storage_dir):
349 340
  """Initialize if needed the file storage.
350 341

  
......
372 363
                               " a directory." % file_storage_dir,
373 364
                               errors.ECODE_ENVIRON)
374 365

  
375
  # FIXME: check here if the file_storage_dir is in the set of allowed dirs
376 366
  return file_storage_dir
377 367

  
378 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.
373

  
374
  """
375
  if file_storage_dir is None:
376
    file_storage_dir = pathutils.DEFAULT_FILE_STORAGE_DIR
377
  if not acceptance_fn:
378
    acceptance_fn = \
379
        lambda path: filestorage.CheckFileStoragePathAcceptance(
380
            path, exact_match_ok=True)
381

  
382
  cluster.CheckFileStoragePathVsEnabledDiskTemplates(
383
      logging.warning, file_storage_dir, enabled_disk_templates)
384

  
385
  file_storage_enabled = constants.DT_FILE in enabled_disk_templates
386
  if file_storage_enabled:
387
    try:
388
      acceptance_fn(file_storage_dir)
389
    except errors.FileStoragePathError as e:
390
      raise errors.OpPrereqError(str(e))
391
    result_file_storage_dir = init_fn(file_storage_dir)
392
  else:
393
    result_file_storage_dir = file_storage_dir
394
  return result_file_storage_dir
395

  
396

  
379 397
def _InitCheckEnabledDiskTemplates(enabled_disk_templates):
380 398
  """Checks the sanity of the enabled disk templates.
381 399

  

Also available in: Unified diff