Commit bf4af505 authored by Apollon Oikonomopoulos's avatar Apollon Oikonomopoulos Committed by Iustin Pop

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: default avatarApollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent c4d3e57f
......@@ -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,
......
......@@ -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)
......
......@@ -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
......
......@@ -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.
......
......@@ -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.
......
......@@ -311,6 +311,7 @@ class OpSetClusterParams(OpCode):
"uid_pool",
"add_uids",
"remove_uids",
"default_iallocator",
]
......
......@@ -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": (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment