From: Apollon Oikonomopoulos <[email protected]> Add shared file storage handling during cluster initialization.
Signed-off-by: Apollon Oikonomopoulos <[email protected]> --- lib/bootstrap.py | 44 +++++++++++++++++++++++++++++++++++++++----- scripts/gnt-cluster | 3 ++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 770568c..4cb79c5 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -210,12 +210,45 @@ def _InitFileStorage(file_storage_dir): return file_storage_dir +def _InitSharedFileStorage(shared_file_storage_dir): + """Initialize if needed the shared file storage. + + @param file_storage_dir: the user-supplied value + @return: either empty string (if file storage was disabled at build + time) or the normalized path to the storage directory + + """ + if not constants.ENABLE_SHARED_FILE_STORAGE: + return "" + + shared_file_storage_dir = os.path.normpath(shared_file_storage_dir) + + if not os.path.isabs(shared_file_storage_dir): + raise errors.OpPrereqError("The shared file storage directory you" + " passed is not an absolute path.", + errors.ECODE_INVAL) + + if not os.path.exists(shared_file_storage_dir): + try: + os.makedirs(shared_file_storage_dir, 0750) + except OSError, err: + raise errors.OpPrereqError("Cannot create file storage directory" + " '%s': %s" % (shared_file_storage_dir, err), + errors.ECODE_ENVIRON) + + if not os.path.isdir(shared_file_storage_dir): + raise errors.OpPrereqError("The file storage directory '%s' is not" + " a directory." % shared_file_storage_dir, + errors.ECODE_ENVIRON) + return shared_file_storage_dir + + def InitCluster(cluster_name, mac_prefix, - master_netdev, file_storage_dir, candidate_pool_size, - secondary_ip=None, vg_name=None, beparams=None, - nicparams=None, hvparams=None, enabled_hypervisors=None, - modify_etc_hosts=True, modify_ssh_setup=True, - maintain_node_health=False, + master_netdev, file_storage_dir, shared_file_storage_dir, + candidate_pool_size, secondary_ip=None, vg_name=None, + beparams=None, nicparams=None, hvparams=None, + enabled_hypervisors=None, modify_etc_hosts=True, + modify_ssh_setup=True, maintain_node_health=False, uid_pool=None): """Initialise the cluster. @@ -280,6 +313,7 @@ def InitCluster(cluster_name, mac_prefix, errors.ECODE_INVAL) file_storage_dir = _InitFileStorage(file_storage_dir) + shared_file_storage_dir = _InitSharedFileStorage(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, diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index fbe8e75..67414dc 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -103,6 +103,7 @@ def InitCluster(opts, args): mac_prefix=opts.mac_prefix, master_netdev=opts.master_netdev, file_storage_dir=opts.file_storage_dir, + shared_file_storage_dir=opts.shared_file_storage_dir, enabled_hypervisors=hvlist, hvparams=hvparams, beparams=beparams, @@ -782,7 +783,7 @@ commands = { HVLIST_OPT, MAC_PREFIX_OPT, MASTER_NETDEV_OPT, NIC_PARAMS_OPT, NOLVM_STORAGE_OPT, NOMODIFY_ETCHOSTS_OPT, NOMODIFY_SSH_SETUP_OPT, SECONDARY_IP_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT, - UIDPOOL_OPT], + UIDPOOL_OPT, GLOBAL_SHARED_FILEDIR_OPT], "[opts...] <cluster_name>", "Initialises a new cluster configuration"), 'destroy': ( DestroyCluster, ARGS_NONE, [YES_DOIT_OPT], -- 1.7.1
