diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 44d8f3d71db9ee002afb01b986bf78d2dc718e92..c7fdd1205a29411e49d60c5ec812a5b7b2485a83 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -218,7 +218,7 @@ def InitCluster(cluster_name, mac_prefix, nicparams=None, hvparams=None, enabled_hypervisors=None, modify_etc_hosts=True, modify_ssh_setup=True, maintain_node_health=False, drbd_helper=None, - uid_pool=None): + uid_pool=None, default_iallocator=None): """Initialise the cluster. @type candidate_pool_size: int @@ -333,6 +333,15 @@ def InitCluster(cluster_name, mac_prefix, if modify_ssh_setup: _InitSSHSetup() + if default_iallocator is not None: + alloc_script = utils.FindFile(default_iallocator, + constants.IALLOCATOR_SEARCH_PATH, + os.path.isfile) + if alloc_script is None: + raise errors.OpPrereqError("Invalid default iallocator script '%s'" + " specified" % default_iallocator, + errors.ECODE_INVAL) + now = time.time() # init of cluster config file @@ -361,6 +370,7 @@ def InitCluster(cluster_name, mac_prefix, uuid=utils.NewUUID(), maintain_node_health=maintain_node_health, drbd_usermode_helper=drbd_helper, + default_iallocator=default_iallocator, ) master_node_config = objects.Node(name=hostname.name, primary_ip=hostname.ip, diff --git a/lib/cli.py b/lib/cli.py index 9f35f06aa92f74bf9ca85ac1e7b3a94a6d8825fd..92680cb610361d31be077ebaa76e308dc00067fd 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -75,6 +75,7 @@ __all__ = [ "HVOPTS_OPT", "HYPERVISOR_OPT", "IALLOCATOR_OPT", + "DEFAULT_IALLOCATOR_OPT", "IDENTIFY_DEFAULTS_OPT", "IGNORE_CONSIST_OPT", "IGNORE_FAILURES_OPT", @@ -615,6 +616,12 @@ IALLOCATOR_OPT = cli_option("-I", "--iallocator", metavar="<NAME>", default=None, type="string", completion_suggest=OPT_COMPL_ONE_IALLOCATOR) +DEFAULT_IALLOCATOR_OPT = cli_option("-I", "--default-iallocator", + metavar="<NAME>", + help="Set the default instance allocator plugin", + default=None, type="string", + completion_suggest=OPT_COMPL_ONE_IALLOCATOR) + OS_OPT = cli_option("-o", "--os-type", dest="os", help="What OS to run", metavar="<os>", completion_suggest=OPT_COMPL_ONE_OS) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index b474c6fdc5d7c89d2c099c80c99f7de5cb8ef55b..550d5b9414eeaa73e5fdf7e7c64b2ce4a2b488aa 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2562,6 +2562,7 @@ class LUSetClusterParams(LogicalUnit): ("maintain_node_health", None, _TMaybeBool), ("nicparams", None, _TOr(_TDict, _TNone)), ("drbd_helper", None, _TOr(_TString, _TNone)), + ("default_iallocator", None, _TMaybeString), ] REQ_BGL = False @@ -2767,6 +2768,14 @@ class LUSetClusterParams(LogicalUnit): hv_class.CheckParameterSyntax(new_osp) _CheckHVParams(self, node_list, hv_name, new_osp) + if self.op.default_iallocator: + alloc_script = utils.FindFile(self.op.default_iallocator, + constants.IALLOCATOR_SEARCH_PATH, + os.path.isfile) + if alloc_script is None: + raise errors.OpPrereqError("Invalid default iallocator script '%s'" + " specified" % self.op.default_iallocator, + errors.ECODE_INVAL) def Exec(self, feedback_fn): """Change the parameters of the cluster. @@ -2821,6 +2830,9 @@ class LUSetClusterParams(LogicalUnit): if self.op.uid_pool is not None: self.cluster.uid_pool = self.op.uid_pool + if self.op.default_iallocator is not None: + self.cluster.default_iallocator = self.op.default_iallocator + self.cfg.Update(self.cluster, feedback_fn) @@ -4083,6 +4095,7 @@ class LUQueryClusterInfo(NoHooksLU): "uuid": cluster.uuid, "tags": list(cluster.GetTags()), "uid_pool": cluster.uid_pool, + "default_iallocator": cluster.default_iallocator, } return result diff --git a/lib/config.py b/lib/config.py index 371a3994b3083e25401bc783c1c980b95bba56a1..e1109b1b9d513aee92a4fa4b5ef1b6db409b2707 100644 --- a/lib/config.py +++ b/lib/config.py @@ -816,6 +816,13 @@ class ConfigWriter: """ return self._config_data.cluster.rsahostkeypub + @locking.ssynchronized(_config_lock, shared=1) + def GetDefaultIAllocator(self): + """Get the default instance allocator for this cluster. + + """ + return self._config_data.cluster.default_iallocator + @locking.ssynchronized(_config_lock) def AddInstance(self, instance, ec_id): """Add an instance to the config. diff --git a/lib/objects.py b/lib/objects.py index 42036e180ad2847050386e34868aa98cd7815efc..be6f2d7148af10efbdd6983aef9fa55a3eb93397 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -917,6 +917,7 @@ class Cluster(TaggableObject): "modify_ssh_setup", "maintain_node_health", "uid_pool", + "default_iallocator", ] + _TIMESTAMPS + _UUID def UpgradeConfig(self): @@ -975,6 +976,9 @@ class Cluster(TaggableObject): if self.uid_pool is None: self.uid_pool = [] + if self.default_iallocator is None: + self.default_iallocator = "" + def ToDict(self): """Custom function for cluster. diff --git a/lib/opcodes.py b/lib/opcodes.py index 0f530f31abf14e1c6255794f722d6861c241929e..0caf9fbf5bd0e9f03f14b9985ac3a5cbaea7f132 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -311,6 +311,7 @@ class OpSetClusterParams(OpCode): "uid_pool", "add_uids", "remove_uids", + "default_iallocator", ] diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index c3101792a93f8bfa8e44ec80f078ce0483d5b846..8d5818b4477648227dd86f2c4659bc40f7ac5b3e 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -121,6 +121,7 @@ def InitCluster(opts, args): maintain_node_health=opts.maintain_node_health, drbd_helper=drbd_helper, uid_pool=uid_pool, + default_iallocator=opts.default_iallocator, ) op = opcodes.OpPostInitCluster() SubmitOpCode(op, opts=opts) @@ -302,6 +303,7 @@ def ShowClusterConfig(opts, args): ToStdout(" - uid pool: %s", uidpool.FormatUidPool(result["uid_pool"], roman=opts.roman_integers)) + ToStdout(" - default instance allocator: %s", result["default_iallocator"]) ToStdout("Default instance parameters:") _PrintGroupedParams(result["beparams"], roman=opts.roman_integers) @@ -660,7 +662,8 @@ def SetClusterParams(opts, args): opts.uid_pool is not None or opts.maintain_node_health is not None or opts.add_uids is not None or - opts.remove_uids is not None): + opts.remove_uids is not None or + opts.default_iallocator is not None): ToStderr("Please give at least one of the parameters.") return 1 @@ -721,7 +724,8 @@ def SetClusterParams(opts, args): maintain_node_health=mnh, uid_pool=uid_pool, add_uids=add_uids, - remove_uids=remove_uids) + remove_uids=remove_uids, + default_iallocator=opts.default_iallocator) SubmitOpCode(op, opts=opts) return 0 @@ -804,7 +808,8 @@ 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, DRBD_HELPER_OPT, NODRBD_STORAGE_OPT], + UIDPOOL_OPT, DRBD_HELPER_OPT, NODRBD_STORAGE_OPT, + DEFAULT_IALLOCATOR_OPT], "[opts...] <cluster_name>", "Initialises a new cluster configuration"), 'destroy': ( DestroyCluster, ARGS_NONE, [YES_DOIT_OPT], @@ -875,7 +880,7 @@ commands = { [BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, HVLIST_OPT, NIC_PARAMS_OPT, NOLVM_STORAGE_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT, UIDPOOL_OPT, ADD_UIDS_OPT, REMOVE_UIDS_OPT, DRBD_HELPER_OPT, - NODRBD_STORAGE_OPT], + NODRBD_STORAGE_OPT, DEFAULT_IALLOCATOR_OPT], "[opts...]", "Alters the parameters of the cluster"), "renew-crypto": (