- add a command line flag to gnt-cluster init and modify to change the value of the cluster parameter use_external_mip_setup_script; - add two constants representing the paths of the default script and of the external script; - add documentation for the new option in the gnt-cluster man page; - add use_external_mip_setup_script to gnt-cluster info output.
Signed-off-by: Andrea Spadaccini <spadac...@google.com> --- lib/bootstrap.py | 4 +++- lib/cli.py | 8 ++++++++ lib/client/gnt_cluster.py | 18 +++++++++++++++--- lib/cmdlib.py | 4 ++++ lib/constants.py | 5 +++++ lib/opcodes.py | 2 ++ man/gnt-cluster.rst | 14 ++++++++++++-- 7 files changed, 49 insertions(+), 6 deletions(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 17df67e..a6b436c 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -289,7 +289,8 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913 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, - primary_ip_version=None, prealloc_wipe_disks=False): + primary_ip_version=None, prealloc_wipe_disks=False, + use_external_mip_setup_script=False): """Initialise the cluster. @type candidate_pool_size: int @@ -482,6 +483,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913 default_iallocator=default_iallocator, primary_ip_family=ipcls.family, prealloc_wipe_disks=prealloc_wipe_disks, + use_external_mip_setup_script=use_external_mip_setup_script, ) master_node_config = objects.Node(name=hostname.name, primary_ip=hostname.ip, diff --git a/lib/cli.py b/lib/cli.py index eeea6ed..38003f6 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -177,6 +177,7 @@ __all__ = [ "TO_GROUP_OPT", "UIDPOOL_OPT", "USEUNITS_OPT", + "USE_EXTERNAL_MIP_SETUP_SCRIPT", "USE_REPL_NET_OPT", "VERBOSE_OPT", "VG_NAME_OPT", @@ -1016,6 +1017,13 @@ MASTER_NETMASK_OPT = cli_option("--master-netmask", dest="master_netmask", metavar="NETMASK", default=None) +USE_EXTERNAL_MIP_SETUP_SCRIPT = cli_option("--use-external-mip-setup-script", + dest="use_external_mip_setup_script", + help="Specify whether to run a user-provided" + " script for the master IP address turnup and" + " turndown operations", + type="bool", metavar=_YORNO, default=None) + GLOBAL_FILEDIR_OPT = cli_option("--file-storage-dir", dest="file_storage_dir", help="Specify the default directory (cluster-" "wide) for storing the file-based disks [%s]" % diff --git a/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py index 26d3c3f..d06de42 100644 --- a/lib/client/gnt_cluster.py +++ b/lib/client/gnt_cluster.py @@ -133,6 +133,10 @@ def InitCluster(opts, args): if opts.prealloc_wipe_disks is None: opts.prealloc_wipe_disks = False + external_ip_setup_script = opts.use_external_mip_setup_script + if external_ip_setup_script is None: + external_ip_setup_script = False + try: primary_ip_version = int(opts.primary_ip_version) except (ValueError, TypeError), err: @@ -169,6 +173,7 @@ def InitCluster(opts, args): default_iallocator=opts.default_iallocator, primary_ip_version=primary_ip_version, prealloc_wipe_disks=opts.prealloc_wipe_disks, + use_external_mip_setup_script=external_ip_setup_script, ) op = opcodes.OpClusterPostInit() SubmitOpCode(op, opts=opts) @@ -381,6 +386,8 @@ def ShowClusterConfig(opts, args): convert=opts.roman_integers)) ToStdout(" - master netdev: %s", result["master_netdev"]) ToStdout(" - master netmask: %s", result["master_netmask"]) + ToStdout(" - use external master IP address setup script: %s", + result["use_external_mip_setup_script"]) ToStdout(" - lvm volume group: %s", result["volume_group_name"]) if result["reserved_lvs"]: reserved_lvs = utils.CommaJoin(result["reserved_lvs"]) @@ -879,6 +886,7 @@ def SetClusterParams(opts, args): opts.reserved_lvs is not None or opts.master_netdev is not None or opts.master_netmask is not None or + opts.use_external_mip_setup_script is not None or opts.prealloc_wipe_disks is not None): ToStderr("Please give at least one of the parameters.") return 1 @@ -945,6 +953,8 @@ def SetClusterParams(opts, args): ToStderr("The --master-netmask option expects an int parameter.") return 1 + ext_ip_script = opts.use_external_mip_setup_script + op = opcodes.OpClusterSetParams(vg_name=vg_name, drbd_helper=drbd_helper, enabled_hypervisors=hvlist, @@ -962,7 +972,9 @@ def SetClusterParams(opts, args): prealloc_wipe_disks=opts.prealloc_wipe_disks, master_netdev=opts.master_netdev, master_netmask=opts.master_netmask, - reserved_lvs=opts.reserved_lvs) + reserved_lvs=opts.reserved_lvs, + use_external_mip_setup_script=ext_ip_script, + ) SubmitOpCode(op, opts=opts) return 0 @@ -1364,7 +1376,7 @@ commands = { NOMODIFY_SSH_SETUP_OPT, 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, GLOBAL_SHARED_FILEDIR_OPT], + NODE_PARAMS_OPT, GLOBAL_SHARED_FILEDIR_OPT, USE_EXTERNAL_MIP_SETUP_SCRIPT], "[opts...] <cluster_name>", "Initialises a new cluster configuration"), "destroy": ( DestroyCluster, ARGS_NONE, [YES_DOIT_OPT], @@ -1441,7 +1453,7 @@ commands = { MAINTAIN_NODE_HEALTH_OPT, UIDPOOL_OPT, ADD_UIDS_OPT, REMOVE_UIDS_OPT, DRBD_HELPER_OPT, NODRBD_STORAGE_OPT, DEFAULT_IALLOCATOR_OPT, RESERVED_LVS_OPT, DRY_RUN_OPT, PRIORITY_OPT, PREALLOC_WIPE_DISKS_OPT, - NODE_PARAMS_OPT], + NODE_PARAMS_OPT, USE_EXTERNAL_MIP_SETUP_SCRIPT], "[opts...]", "Alters the parameters of the cluster"), "renew-crypto": ( diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 68601c7..58b1955 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -3683,6 +3683,10 @@ class LUClusterSetParams(LogicalUnit): if self.op.reserved_lvs is not None: self.cluster.reserved_lvs = self.op.reserved_lvs + if self.op.use_external_mip_setup_script is not None: + self.cluster.use_external_mip_setup_script = \ + self.op.use_external_mip_setup_script + def helper_os(aname, mods, desc): desc += " OS list" lst = getattr(self.cluster, aname) diff --git a/lib/constants.py b/lib/constants.py index 0b0ad4f..39d4c72 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -180,6 +180,7 @@ ENABLE_SHARED_FILE_STORAGE = _autoconf.ENABLE_SHARED_FILE_STORAGE SYSCONFDIR = _autoconf.SYSCONFDIR TOOLSDIR = _autoconf.TOOLSDIR CONF_DIR = SYSCONFDIR + "/ganeti" +USER_SCRIPTS_DIR = CONF_DIR + "/scripts" #: Lock file for watcher, locked in shared mode by watcher; lock in exclusive # mode to block watcher (see L{cli._RunWhileClusterStoppedHelper.Call} @@ -195,6 +196,10 @@ WATCHER_GROUP_INSTANCE_STATUS_FILE = DATA_DIR + "/watcher.%s.instance-status" #: File containing Unix timestamp until which watcher should be paused WATCHER_PAUSEFILE = DATA_DIR + "/watcher.pause" +# Master IP address setup scripts paths (default and user-provided) +DEFAULT_MASTER_SETUP_SCRIPT = TOOLSDIR + "/master-ip-setup" +EXTERNAL_MASTER_SETUP_SCRIPT = USER_SCRIPTS_DIR + "/master-ip-setup" + ALL_CERT_FILES = frozenset([ NODED_CERT_FILE, RAPI_CERT_FILE, diff --git a/lib/opcodes.py b/lib/opcodes.py index fb8b858..24e22b2 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -796,6 +796,8 @@ class OpClusterSetParams(OpCode): "Modify list of blacklisted operating systems. Each modification must have" " two items, the operation and the OS name. The operation can be" " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)), + ("use_external_mip_setup_script", None, ht.TMaybeBool, + "Whether to use an external master IP address setup script"), ] diff --git a/man/gnt-cluster.rst b/man/gnt-cluster.rst index 7107a43..bf72c6e 100644 --- a/man/gnt-cluster.rst +++ b/man/gnt-cluster.rst @@ -167,6 +167,7 @@ INIT | [--vg-name *vg-name*] | [--master-netdev *interface-name*] | [--master-netmask *netmask*] +| [--use-external-mip-setup-script {yes \| no}] | [{-m|--mac-prefix} *mac-prefix*] | [--no-lvm-storage] | [--no-etc-hosts] @@ -228,6 +229,13 @@ master IP. The netmask must be specified as an integer, and will be interpreted as a CIDR netmask. The default value is 32 for an IPv4 address and 128 for an IPv6 address. +The ``--use-external-mip-setup-script`` options allows to specify +whether to use an user-supplied master IP address setup script, whose +default location is ``/etc/ganeti/scripts/master-ip-setup``. If +the option value is set to False, the default script, whose default +location is ``/usr/local/lib/ganeti/tools/master-ip-setup``, will be +executed. + The ``-m (--mac-prefix)`` option will let you specify a three byte prefix under which the virtual MAC addresses of your instances will be generated. The prefix must be specified in the format ``XX:XX:XX`` and @@ -438,6 +446,7 @@ MODIFY | [--node-parameters *ndparams*] | [--master-netdev *interface-name*] | [--master-netmask *netmask*] +| [--use-external-mip-setup-script {yes \| no}] Modify the options for the cluster. @@ -445,8 +454,9 @@ The ``--vg-name``, ``--no-lvm-storarge``, ``--enabled-hypervisors``, ``-H (--hypervisor-parameters)``, ``-B (--backend-parameters)``, ``--nic-parameters``, ``-C (--candidate-pool-size)``, ``--maintain-node-health``, ``--prealloc-wipe-disks``, ``--uid-pool``, -``--node-parameters``, ``--master-netdev`` and ``--master-netmask`` -options are described in the **init** command. +``--node-parameters``, ``--master-netdev``, ``--master-netmask`` and +``--use-external-mip-setup-script`` options are described in the +**init** command. The ``--add-uids`` and ``--remove-uids`` options can be used to modify the user-id pool by adding/removing a list of user-ids or -- 1.7.3.1