Commit e8b5640e authored by Helga Velroyen's avatar Helga Velroyen

Bootstrap: factor out and prepare shared-file-storage

This patch makes 'gnt-cluster init' use the
'--shared-file-storage-dir' option to set the default
shared file storage dir. Additionally, it performs the
same sanity and validity checks for the path as for
the default file storage directory. For this, we tried
to re-use as much code from file storage as possible.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarThomas Thrainer <thomasth@google.com>
parent 753d0fed
......@@ -366,14 +366,29 @@ def _InitFileStorageDir(file_storage_dir):
return file_storage_dir
def _PrepareFileStorage(
enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir,
acceptance_fn=None):
"""Checks if file storage is enabled and inits the dir.
def _PrepareFileBasedStorage(
enabled_disk_templates, file_storage_dir,
default_dir, file_disk_template,
init_fn=_InitFileStorageDir, acceptance_fn=None):
"""Checks if a file-base storage type is enabled and inits the dir.
@type enabled_disk_templates: list of string
@param enabled_disk_templates: list of enabled disk templates
@type file_storage_dir: string
@param file_storage_dir: the file storage directory
@type default_dir: string
@param default_dir: default file storage directory when C{file_storage_dir}
is 'None'
@type file_disk_template: string
@param file_disk_template: a disk template whose storage type is 'ST_FILE'
@rtype: string
@returns: the name of the actual file storage directory
"""
assert (file_disk_template in
utils.storage.GetDiskTemplatesOfStorageType(constants.ST_FILE))
if file_storage_dir is None:
file_storage_dir = pathutils.DEFAULT_FILE_STORAGE_DIR
file_storage_dir = default_dir
if not acceptance_fn:
acceptance_fn = \
lambda path: filestorage.CheckFileStoragePathAcceptance(
......@@ -382,7 +397,7 @@ def _PrepareFileStorage(
cluster.CheckFileStoragePathVsEnabledDiskTemplates(
logging.warning, file_storage_dir, enabled_disk_templates)
file_storage_enabled = constants.DT_FILE in enabled_disk_templates
file_storage_enabled = file_disk_template in enabled_disk_templates
if file_storage_enabled:
try:
acceptance_fn(file_storage_dir)
......@@ -394,6 +409,34 @@ def _PrepareFileStorage(
return result_file_storage_dir
def _PrepareFileStorage(
enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir,
acceptance_fn=None):
"""Checks if file storage is enabled and inits the dir.
@see: C{_PrepareFileBasedStorage}
"""
return _PrepareFileBasedStorage(
enabled_disk_templates, file_storage_dir,
pathutils.DEFAULT_FILE_STORAGE_DIR, constants.DT_FILE,
init_fn=init_fn, acceptance_fn=acceptance_fn)
def _PrepareSharedFileStorage(
enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir,
acceptance_fn=None):
"""Checks if shared file storage is enabled and inits the dir.
@see: C{_PrepareFileBasedStorage}
"""
return _PrepareFileBasedStorage(
enabled_disk_templates, file_storage_dir,
pathutils.DEFAULT_SHARED_FILE_STORAGE_DIR, constants.DT_SHARED_FILE,
init_fn=init_fn, acceptance_fn=acceptance_fn)
def _InitCheckEnabledDiskTemplates(enabled_disk_templates):
"""Checks the sanity of the enabled disk templates.
......@@ -529,11 +572,8 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
file_storage_dir = _PrepareFileStorage(enabled_disk_templates,
file_storage_dir)
if constants.ENABLE_SHARED_FILE_STORAGE:
shared_file_storage_dir = _InitFileStorageDir(shared_file_storage_dir)
else:
shared_file_storage_dir = ""
shared_file_storage_dir = _PrepareSharedFileStorage(enabled_disk_templates,
shared_file_storage_dir)
if not re.match("^[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}$", mac_prefix):
raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix,
......
......@@ -609,9 +609,12 @@ def _ValidateNetmask(cfg, netmask):
(netmask), errors.ECODE_INVAL)
def CheckFileStoragePathVsEnabledDiskTemplates(
logging_warn_fn, file_storage_dir, enabled_disk_templates):
"""Checks whether the given file storage directory is acceptable.
def CheckFileBasedStoragePathVsEnabledDiskTemplates(
logging_warn_fn, file_storage_dir, enabled_disk_templates,
file_disk_template):
"""Checks whether the given file-based storage directory is acceptable.
Note: This function is public, because it is also used in bootstrap.py.
@type logging_warn_fn: function
@param logging_warn_fn: function which accepts a string and logs it
......@@ -619,23 +622,53 @@ def CheckFileStoragePathVsEnabledDiskTemplates(
@param file_storage_dir: the directory to be used for file-based instances
@type enabled_disk_templates: list of string
@param enabled_disk_templates: the list of enabled disk templates
@type file_disk_template: string
@param file_disk_template: the file-based disk template for which the
path should be checked
Note: This function is public, because it is also used in bootstrap.py.
"""
file_storage_enabled = constants.DT_FILE in enabled_disk_templates
assert (file_disk_template in
utils.storage.GetDiskTemplatesOfStorageType(constants.ST_FILE))
file_storage_enabled = file_disk_template in enabled_disk_templates
if file_storage_dir is not None:
if file_storage_dir == "":
if file_storage_enabled:
raise errors.OpPrereqError("Unsetting the file storage directory"
" while having file storage enabled"
" is not permitted.")
raise errors.OpPrereqError(
"Unsetting the '%s' storage directory while having '%s' storage"
" enabled is not permitted." %
(file_disk_template, file_disk_template))
else:
if not file_storage_enabled:
logging_warn_fn("Specified a file storage directory, although file"
" storage is not enabled.")
logging_warn_fn(
"Specified a %s storage directory, although %s storage is not"
" enabled." % (file_disk_template, file_disk_template))
else:
raise errors.ProgrammerError("Received file storage dir with value"
" 'None'.")
raise errors.ProgrammerError("Received %s storage dir with value"
" 'None'." % file_disk_template)
def CheckFileStoragePathVsEnabledDiskTemplates(
logging_warn_fn, file_storage_dir, enabled_disk_templates):
"""Checks whether the given file storage directory is acceptable.
@see: C{CheckFileBasedStoragePathVsEnabledDiskTemplates}
"""
CheckFileBasedStoragePathVsEnabledDiskTemplates(
logging_warn_fn, file_storage_dir, enabled_disk_templates,
constants.DT_FILE)
def CheckSharedFileStoragePathVsEnabledDiskTemplates(
logging_warn_fn, file_storage_dir, enabled_disk_templates):
"""Checks whether the given shared file storage directory is acceptable.
@see: C{CheckFileBasedStoragePathVsEnabledDiskTemplates}
"""
CheckFileBasedStoragePathVsEnabledDiskTemplates(
logging_warn_fn, file_storage_dir, enabled_disk_templates,
constants.DT_SHARED_FILE)
class LUClusterSetParams(LogicalUnit):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment