diff --git a/lib/bootstrap.py b/lib/bootstrap.py index fd7ff835a7cea0531491cb0329889f756fc1e59b..04ca5058d77a81ad1cfb4dc333c7dd58174ecebc 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2008, 2010 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2010, 2011 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -245,10 +245,43 @@ def _InitFileStorage(file_storage_dir): return file_storage_dir +def _InitSharedFileStorage(shared_file_storage_dir): + """Initialize if needed the shared file storage. + + @param shared_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, # pylint: disable-msg=R0913 - master_netdev, file_storage_dir, candidate_pool_size, - secondary_ip=None, vg_name=None, beparams=None, - nicparams=None, ndparams=None, hvparams=None, + master_netdev, file_storage_dir, shared_file_storage_dir, + candidate_pool_size, secondary_ip=None, vg_name=None, + beparams=None, nicparams=None, ndparams=None, hvparams=None, enabled_hypervisors=None, modify_etc_hosts=True, modify_ssh_setup=True, maintain_node_health=False, drbd_helper=None, uid_pool=None, default_iallocator=None, @@ -347,6 +380,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable-msg=R0913 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/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py index 981696fef7604e88217aa9c1969aaf719a74f4c8..f83f894e98a7a4c7485de4dd6b9bce2a6090bc1b 100644 --- a/lib/client/gnt_cluster.py +++ b/lib/client/gnt_cluster.py @@ -145,6 +145,7 @@ def InitCluster(opts, args): mac_prefix=opts.mac_prefix, master_netdev=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, @@ -1223,7 +1224,7 @@ commands = { SECONDARY_IP_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT, UIDPOOL_OPT, DRBD_HELPER_OPT, NODRBD_STORAGE_OPT, DEFAULT_IALLOCATOR_OPT, PRIMARY_IP_VERSION_OPT, PREALLOC_WIPE_DISKS_OPT, - NODE_PARAMS_OPT], + NODE_PARAMS_OPT, GLOBAL_SHARED_FILEDIR_OPT], "[opts...] <cluster_name>", "Initialises a new cluster configuration"), 'destroy': ( DestroyCluster, ARGS_NONE, [YES_DOIT_OPT],