From bf4af505c29f38f6f2bc4de33a4f2fb166640b8a Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Date: Thu, 8 Jul 2010 15:02:55 +0300
Subject: [PATCH] Add default_iallocator cluster parameter
Add a cluster parameter to hold the iallocator that will be used by default
when required and no alternative (manually-specified iallocator or
manually-specified node(s)) is given.
Signed-off-by: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
lib/bootstrap.py | 12 +++++++++++-
lib/cli.py | 7 +++++++
lib/cmdlib.py | 13 +++++++++++++
lib/config.py | 7 +++++++
lib/objects.py | 4 ++++
lib/opcodes.py | 1 +
scripts/gnt-cluster | 13 +++++++++----
7 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 44d8f3d71..c7fdd1205 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 9f35f06aa..92680cb61 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 b474c6fdc..550d5b941 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 371a3994b..e1109b1b9 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 42036e180..be6f2d714 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 0f530f31a..0caf9fbf5 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 c3101792a..8d5818b44 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": (
--
GitLab