def ExtStorageFromDisk(name, base_dir=None):
  if base_dir is None:
    es_base_dir = pathutils.ES_SEARCH_PATH
  else:
    es_base_dir = [base_dir]

  es_dir = utils.FindFile(name, es_base_dir, os.path.isdir)

  if es_dir is None:
    return False, ("Directory for External Storage Provider %s not"
                   " found in search path" % name)

  # ES Files dictionary: this will be populated later with the absolute path
  # names for each script; currently we denote for each script if it is
  # required (True) or optional (False)
  es_files = dict.fromkeys(constants.ES_SCRIPTS, True)

  # Let the snapshot, open, and close scripts be optional
  # for backwards compatibility
  es_files[constants.ES_SCRIPT_SNAPSHOT] = False
  es_files[constants.ES_SCRIPT_OPEN] = False
  es_files[constants.ES_SCRIPT_CLOSE] = False

  es_files[constants.ES_PARAMETERS_FILE] = True

  for (filename, required) in es_files.items():
    try:
      # Here we actually fill the dict with the ablsolute path name for each
      # script or None, depending on the corresponding checks. See the
      # function's docstrings for more on these checks.
      es_files[filename] = _CheckExtStorageFile(es_dir, filename, required)
    except errors.BlockDeviceError, err:
      return False, str(err)

  parameters = []
  if constants.ES_PARAMETERS_FILE in es_files:
    parameters_file = es_files[constants.ES_PARAMETERS_FILE]
    try:
      parameters = utils.ReadFile(parameters_file).splitlines()
    except EnvironmentError, err:
      return False, ("Error while reading the EXT parameters file at %s: %s" %
                     (parameters_file, utils.ErrnoOrStr(err)))
    parameters = [v.split(None, 1) for v in parameters]

  es_obj = \
    objects.ExtStorage(name=name, path=es_dir,
                       create_script=es_files[constants.ES_SCRIPT_CREATE],
                       remove_script=es_files[constants.ES_SCRIPT_REMOVE],
                       grow_script=es_files[constants.ES_SCRIPT_GROW],
                       attach_script=es_files[constants.ES_SCRIPT_ATTACH],
                       detach_script=es_files[constants.ES_SCRIPT_DETACH],
                       setinfo_script=es_files[constants.ES_SCRIPT_SETINFO],
                       verify_script=es_files[constants.ES_SCRIPT_VERIFY],
                       snapshot_script=es_files[constants.ES_SCRIPT_SNAPSHOT],
                       open_script=es_files[constants.ES_SCRIPT_OPEN],
                       close_script=es_files[constants.ES_SCRIPT_CLOSE],
                       supported_parameters=parameters)
  return True, es_obj
Create an ExtStorage instance from disk.
dataset/ETHPy150Open ganeti/ganeti/lib/storage/extstorage.py/ExtStorageFromDisk