Commit 0359e5d0 authored by Spyros Trigazis's avatar Spyros Trigazis Committed by Michele Tartara

Add default_iallocator_params cluster parameter

Add a cluster parameter to hold the iallocator parameters used
by the default instance allocator. Implement the option to
modify config.data, query config.data and upgrade man pages,
tests and cfgupgrade tool. The new default_iallocator_params is
an empty dict by default.
Signed-off-by: default avatarSpyros Trigazis <strigazi@gmail.com>
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 869cea98
......@@ -4490,13 +4490,15 @@ class IAllocatorRunner(object):
"""
@staticmethod
def Run(name, idata):
def Run(name, idata, ial_params):
"""Run an iallocator script.
@type name: str
@param name: the iallocator script name
@type idata: str
@param idata: the allocator input data
@type ial_params: list
@param ial_params: the iallocator parameters
@rtype: tuple
@return: two element tuple of:
......@@ -4513,7 +4515,7 @@ class IAllocatorRunner(object):
try:
os.write(fd, idata)
os.close(fd)
result = utils.RunCmd([alloc_script, fin_name])
result = utils.RunCmd([alloc_script, fin_name] + ial_params)
if result.failed:
_Fail("iallocator module '%s' failed: %s, output '%s'",
name, result.fail_reason, result.output)
......
......@@ -512,7 +512,8 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
hvparams=None, diskparams=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, ipolicy=None,
default_iallocator=None, default_iallocator_params=None,
primary_ip_version=None, ipolicy=None,
prealloc_wipe_disks=False, use_external_mip_script=False,
hv_state=None, disk_state=None, enabled_disk_templates=None):
"""Initialise the cluster.
......@@ -762,6 +763,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
maintain_node_health=maintain_node_health,
drbd_usermode_helper=drbd_helper,
default_iallocator=default_iallocator,
default_iallocator_params=default_iallocator_params,
primary_ip_family=ipcls.family,
prealloc_wipe_disks=prealloc_wipe_disks,
use_external_mip_script=use_external_mip_script,
......
......@@ -102,6 +102,7 @@ __all__ = [
"HYPERVISOR_OPT",
"IALLOCATOR_OPT",
"DEFAULT_IALLOCATOR_OPT",
"DEFAULT_IALLOCATOR_PARAMS_OPT",
"IDENTIFY_DEFAULTS_OPT",
"IGNORE_CONSIST_OPT",
"IGNORE_ERRORS_OPT",
......@@ -912,6 +913,15 @@ DEFAULT_IALLOCATOR_OPT = cli_option("-I", "--default-iallocator",
default=None, type="string",
completion_suggest=OPT_COMPL_ONE_IALLOCATOR)
DEFAULT_IALLOCATOR_PARAMS_OPT = cli_option("--default-iallocator-params",
dest="default_iallocator_params",
help="iallocator template"
" parameters, in the format"
" template:option=value,"
" option=value,...",
type="keyval",
default={})
OS_OPT = cli_option("-o", "--os-type", dest="os", help="What OS to run",
metavar="<os>",
completion_suggest=OPT_COMPL_ONE_OS)
......
......@@ -264,6 +264,7 @@ def InitCluster(opts, args):
hv_state = dict(opts.hv_state)
default_ialloc_params = opts.default_iallocator_params
bootstrap.InitCluster(cluster_name=args[0],
secondary_ip=opts.secondary_ip,
vg_name=vg_name,
......@@ -286,6 +287,7 @@ def InitCluster(opts, args):
drbd_helper=drbd_helper,
uid_pool=uid_pool,
default_iallocator=opts.default_iallocator,
default_iallocator_params=default_ialloc_params,
primary_ip_version=primary_ip_version,
prealloc_wipe_disks=opts.prealloc_wipe_disks,
use_external_mip_script=external_ip_setup_script,
......@@ -524,6 +526,8 @@ def ShowClusterConfig(opts, args):
("maintenance of node health", result["maintain_node_health"]),
("uid pool", uidpool.FormatUidPool(result["uid_pool"])),
("default instance allocator", result["default_iallocator"]),
("default instance allocator parameters",
result["default_iallocator_params"]),
("primary ip version", result["primary_ip_version"]),
("preallocation wipe disks", result["prealloc_wipe_disks"]),
("OS search path", utils.CommaJoin(pathutils.OS_SEARCH_PATH)),
......@@ -1078,6 +1082,7 @@ def SetClusterParams(opts, args):
opts.add_uids is not None or
opts.remove_uids is not None or
opts.default_iallocator is not None or
opts.default_iallocator_params or
opts.reserved_lvs is not None or
opts.master_netdev is not None or
opts.master_netmask is not None or
......@@ -1191,6 +1196,7 @@ def SetClusterParams(opts, args):
add_uids=add_uids,
remove_uids=remove_uids,
default_iallocator=opts.default_iallocator,
default_iallocator_params=opts.default_iallocator_params,
prealloc_wipe_disks=opts.prealloc_wipe_disks,
master_netdev=opts.master_netdev,
master_netmask=opts.master_netmask,
......@@ -2032,10 +2038,11 @@ commands = {
HVLIST_OPT, MAC_PREFIX_OPT, MASTER_NETDEV_OPT, MASTER_NETMASK_OPT,
NIC_PARAMS_OPT, NOMODIFY_ETCHOSTS_OPT, NOMODIFY_SSH_SETUP_OPT,
SECONDARY_IP_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT, UIDPOOL_OPT,
DRBD_HELPER_OPT, DEFAULT_IALLOCATOR_OPT, PRIMARY_IP_VERSION_OPT,
PREALLOC_WIPE_DISKS_OPT, NODE_PARAMS_OPT, GLOBAL_SHARED_FILEDIR_OPT,
USE_EXTERNAL_MIP_SCRIPT, DISK_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT,
ENABLED_DISK_TEMPLATES_OPT, IPOLICY_STD_SPECS_OPT]
DRBD_HELPER_OPT, DEFAULT_IALLOCATOR_OPT, DEFAULT_IALLOCATOR_PARAMS_OPT,
PRIMARY_IP_VERSION_OPT, PREALLOC_WIPE_DISKS_OPT, NODE_PARAMS_OPT,
GLOBAL_SHARED_FILEDIR_OPT, USE_EXTERNAL_MIP_SCRIPT, DISK_PARAMS_OPT,
HV_STATE_OPT, DISK_STATE_OPT, ENABLED_DISK_TEMPLATES_OPT,
IPOLICY_STD_SPECS_OPT]
+ INSTANCE_POLICY_OPTS + SPLIT_ISPECS_OPTS,
"[opts...] <cluster_name>", "Initialises a new cluster configuration"),
"destroy": (
......@@ -2113,9 +2120,10 @@ commands = {
BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, HVLIST_OPT, MASTER_NETDEV_OPT,
MASTER_NETMASK_OPT, NIC_PARAMS_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT,
UIDPOOL_OPT, ADD_UIDS_OPT, REMOVE_UIDS_OPT, DRBD_HELPER_OPT,
DEFAULT_IALLOCATOR_OPT, RESERVED_LVS_OPT, DRY_RUN_OPT, PRIORITY_OPT,
PREALLOC_WIPE_DISKS_OPT, NODE_PARAMS_OPT, USE_EXTERNAL_MIP_SCRIPT,
DISK_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT] + SUBMIT_OPTS +
DEFAULT_IALLOCATOR_OPT, DEFAULT_IALLOCATOR_PARAMS_OPT, RESERVED_LVS_OPT,
DRY_RUN_OPT, PRIORITY_OPT, PREALLOC_WIPE_DISKS_OPT, NODE_PARAMS_OPT,
USE_EXTERNAL_MIP_SCRIPT, DISK_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT] +
SUBMIT_OPTS +
[ENABLED_DISK_TEMPLATES_OPT, IPOLICY_STD_SPECS_OPT, MODIFY_ETCHOSTS_OPT] +
INSTANCE_POLICY_OPTS + [GLOBAL_FILEDIR_OPT],
"[opts...]",
......
......@@ -343,6 +343,7 @@ class LUClusterQuery(NoHooksLU):
"tags": list(cluster.GetTags()),
"uid_pool": cluster.uid_pool,
"default_iallocator": cluster.default_iallocator,
"default_iallocator_params": cluster.default_iallocator_params,
"reserved_lvs": cluster.reserved_lvs,
"primary_ip_version": primary_ip_version,
"prealloc_wipe_disks": cluster.prealloc_wipe_disks,
......@@ -1287,6 +1288,9 @@ class LUClusterSetParams(LogicalUnit):
if self.op.default_iallocator is not None:
self.cluster.default_iallocator = self.op.default_iallocator
if self.op.default_iallocator_params is not None:
self.cluster.default_iallocator_params = self.op.default_iallocator_params
if self.op.reserved_lvs is not None:
self.cluster.reserved_lvs = self.op.reserved_lvs
......
......@@ -1202,6 +1202,16 @@ class ConfigWriter(object):
"""
return self._config_data.cluster.default_iallocator
@locking.ssynchronized(_config_lock, shared=1)
def GetDefaultIAllocatorParameters(self):
"""Get the default instance allocator parameters for this cluster.
@rtype: dict
@return: dict of iallocator parameters
"""
return self._config_data.cluster.default_iallocator_params
@locking.ssynchronized(_config_lock, shared=1)
def GetPrimaryIPFamily(self):
"""Get cluster primary ip family.
......
......@@ -777,7 +777,9 @@ class IAllocator(object):
if call_fn is None:
call_fn = self.rpc.call_iallocator_runner
result = call_fn(self.cfg.GetMasterNode(), name, self.in_text)
ial_params = self.cfg.GetDefaultIAllocatorParameters()
result = call_fn(self.cfg.GetMasterNode(), name, self.in_text, ial_params)
result.Raise("Failure while running the iallocator script")
self.out_text = result.payload
......
......@@ -1573,6 +1573,7 @@ class Cluster(TaggableObject):
"maintain_node_health",
"uid_pool",
"default_iallocator",
"default_iallocator_params",
"hidden_os",
"blacklisted_os",
"primary_ip_family",
......@@ -1646,6 +1647,9 @@ class Cluster(TaggableObject):
if self.default_iallocator is None:
self.default_iallocator = ""
if self.default_iallocator_params is None:
self.default_iallocator_params = {}
# reserved_lvs added before 2.2
if self.reserved_lvs is None:
self.reserved_lvs = []
......
......@@ -542,6 +542,7 @@ _MISC_CALLS = [
("iallocator_runner", SINGLE, None, constants.RPC_TMO_NORMAL, [
("name", None, "Iallocator name"),
("idata", None, "JSON-encoded input string"),
("default_iallocator_params", None, "Additional iallocator parameters"),
], None, None, "Call an iallocator on a remote node"),
("test_delay", MULTI, None, _TestDelayTimeout, [
("duration", None, None),
......
......@@ -987,9 +987,12 @@ class NodeRequestHandler(http.server.HttpServerHandler):
"""Run an iallocator script.
"""
name, idata = params
name, idata, ial_params_dict = params
ial_params = []
for ial_param in ial_params_dict.items():
ial_params.append("--" + ial_param[0] + "=" + ial_param[1])
iar = backend.IAllocatorRunner()
return iar.Run(name, idata)
return iar.Run(name, idata, ial_params)
# test -----------------------
......
......@@ -182,6 +182,7 @@ INIT
| [\--maintain-node-health {yes \| no}]
| [\--uid-pool *user-id pool definition*]
| [{-I|\--default-iallocator} *default instance allocator*]
| [\--default-iallocator-params *ial-param*=*value*,*ial-param*=*value*]
| [\--primary-ip-version *version*]
| [\--prealloc-wipe-disks {yes \| no}]
| [\--node-parameters *ndparams*]
......@@ -512,6 +513,10 @@ the default iallocator will be **hail**\(1) (assuming it can be found
on disk). The default iallocator can be changed later using the
**modify** command.
The option ``--default-iallocator-params`` sets the cluster-wide
iallocator parameters used by the default iallocator only on instance
allocations.
The ``--primary-ip-version`` option specifies the IP version used
for the primary address. Possible values are 4 and 6 for IPv4 and
IPv6, respectively. This option is used when resolving node names
......@@ -636,6 +641,7 @@ MODIFY
| [\--maintain-node-health {yes \| no}]
| [\--prealloc-wipe-disks {yes \| no}]
| [{-I|\--default-iallocator} *default instance allocator*]
| [\--default-iallocator-params *ial-param*=*value*,*ial-param*=*value*]
| [\--reserved-lvs=*NAMES*]
| [\--node-parameters *ndparams*]
| [\--master-netdev *interface-name*]
......@@ -688,6 +694,10 @@ The ``-I (--default-iallocator)`` is described in the **init**
command. To clear the default iallocator, just pass an empty string
('').
The option ``--default-iallocator-params`` is described in the **init**
command. To clear the default iallocator parameters, just pass an empty
string ('').
The ``--ipolicy-...`` options are described in the **init** command.
See **ganeti**\(7) for a description of ``--submit`` and other common
......
......@@ -85,6 +85,7 @@ module Ganeti.Objects
, Ip4Network(..)
, readIp4Address
, nextIp4Address
, IAllocatorParams
) where
import Control.Applicative
......@@ -646,47 +647,51 @@ type ClusterNicParams = Container FilledNicParams
-- | Cluster UID Pool, list (low, high) UID ranges.
type UidPool = [(Int, Int)]
-- | The iallocator parameters type.
type IAllocatorParams = Container JSValue
-- * Cluster definitions
$(buildObject "Cluster" "cluster" $
[ simpleField "rsahostkeypub" [t| String |]
[ simpleField "rsahostkeypub" [t| String |]
, optionalField $
simpleField "dsahostkeypub" [t| String |]
, simpleField "highest_used_port" [t| Int |]
, simpleField "tcpudp_port_pool" [t| [Int] |]
, simpleField "mac_prefix" [t| String |]
simpleField "dsahostkeypub" [t| String |]
, simpleField "highest_used_port" [t| Int |]
, simpleField "tcpudp_port_pool" [t| [Int] |]
, simpleField "mac_prefix" [t| String |]
, optionalField $
simpleField "volume_group_name" [t| String |]
, simpleField "reserved_lvs" [t| [String] |]
simpleField "volume_group_name" [t| String |]
, simpleField "reserved_lvs" [t| [String] |]
, optionalField $
simpleField "drbd_usermode_helper" [t| String |]
, simpleField "master_node" [t| String |]
, simpleField "master_ip" [t| String |]
, simpleField "master_netdev" [t| String |]
, simpleField "master_netmask" [t| Int |]
, simpleField "use_external_mip_script" [t| Bool |]
, simpleField "cluster_name" [t| String |]
, simpleField "file_storage_dir" [t| String |]
, simpleField "shared_file_storage_dir" [t| String |]
, simpleField "enabled_hypervisors" [t| [Hypervisor] |]
, simpleField "hvparams" [t| ClusterHvParams |]
, simpleField "os_hvp" [t| OsHvParams |]
, simpleField "beparams" [t| ClusterBeParams |]
, simpleField "osparams" [t| ClusterOsParams |]
, simpleField "nicparams" [t| ClusterNicParams |]
, simpleField "ndparams" [t| FilledNDParams |]
, simpleField "diskparams" [t| DiskParams |]
, simpleField "candidate_pool_size" [t| Int |]
, simpleField "modify_etc_hosts" [t| Bool |]
, simpleField "modify_ssh_setup" [t| Bool |]
, simpleField "maintain_node_health" [t| Bool |]
, simpleField "uid_pool" [t| UidPool |]
, simpleField "default_iallocator" [t| String |]
, simpleField "hidden_os" [t| [String] |]
, simpleField "blacklisted_os" [t| [String] |]
, simpleField "primary_ip_family" [t| IpFamily |]
, simpleField "prealloc_wipe_disks" [t| Bool |]
, simpleField "ipolicy" [t| FilledIPolicy |]
, simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
simpleField "drbd_usermode_helper" [t| String |]
, simpleField "master_node" [t| String |]
, simpleField "master_ip" [t| String |]
, simpleField "master_netdev" [t| String |]
, simpleField "master_netmask" [t| Int |]
, simpleField "use_external_mip_script" [t| Bool |]
, simpleField "cluster_name" [t| String |]
, simpleField "file_storage_dir" [t| String |]
, simpleField "shared_file_storage_dir" [t| String |]
, simpleField "enabled_hypervisors" [t| [Hypervisor] |]
, simpleField "hvparams" [t| ClusterHvParams |]
, simpleField "os_hvp" [t| OsHvParams |]
, simpleField "beparams" [t| ClusterBeParams |]
, simpleField "osparams" [t| ClusterOsParams |]
, simpleField "nicparams" [t| ClusterNicParams |]
, simpleField "ndparams" [t| FilledNDParams |]
, simpleField "diskparams" [t| DiskParams |]
, simpleField "candidate_pool_size" [t| Int |]
, simpleField "modify_etc_hosts" [t| Bool |]
, simpleField "modify_ssh_setup" [t| Bool |]
, simpleField "maintain_node_health" [t| Bool |]
, simpleField "uid_pool" [t| UidPool |]
, simpleField "default_iallocator" [t| String |]
, simpleField "default_iallocator_params" [t| IAllocatorParams |]
, simpleField "hidden_os" [t| [String] |]
, simpleField "blacklisted_os" [t| [String] |]
, simpleField "primary_ip_family" [t| IpFamily |]
, simpleField "prealloc_wipe_disks" [t| Bool |]
, simpleField "ipolicy" [t| FilledIPolicy |]
, simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
]
++ timeStampFields
++ uuidFields
......
......@@ -225,6 +225,7 @@ $(genOpCode "OpCode"
, withDoc "Cluster-wide ipolicy specs" pIpolicy
, pDrbdHelper
, pDefaultIAllocator
, pDefaultIAllocatorParams
, pMasterNetdev
, pMasterNetmask
, pReservedLvs
......
......@@ -129,6 +129,7 @@ module Ganeti.OpParams
, pIpolicy
, pDrbdHelper
, pDefaultIAllocator
, pDefaultIAllocatorParams
, pMasterNetdev
, pMasterNetmask
, pReservedLvs
......@@ -667,6 +668,11 @@ pDefaultIAllocator =
withDoc "Default iallocator for cluster" $
optionalStringField "default_iallocator"
pDefaultIAllocatorParams :: Field
pDefaultIAllocatorParams =
withDoc "Default iallocator parameters for cluster" . optionalField
$ simpleField "default_iallocator_params" [t| JSObject JSValue |]
pMasterNetdev :: Field
pMasterNetdev =
withDoc "Master network device" $
......
......@@ -145,6 +145,8 @@ handleCall _ cdata QueryClusterInfo =
, ("uid_pool", showJSON $ clusterUidPool cluster)
, ("default_iallocator",
showJSON $ clusterDefaultIallocator cluster)
, ("default_iallocator_params",
showJSON $ clusterDefaultIallocatorParams cluster)
, ("reserved_lvs", showJSON $ clusterReservedLvs cluster)
, ("primary_ip_version",
showJSON . ipFamilyToVersion $ clusterPrimaryIpFamily cluster)
......
......@@ -228,6 +228,9 @@ instance Arbitrary ClusterBeParams where
instance Arbitrary TagSet where
arbitrary = Set.fromList <$> genTags
instance Arbitrary IAllocatorParams where
arbitrary = return $ GenericContainer Map.empty
$(genArbitrary ''Cluster)
instance Arbitrary Network where
......
......@@ -178,7 +178,7 @@ instance Arbitrary OpCodes.OpCode where
arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*>
emptyMUD <*> emptyMUD <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> emptyMUD <*> arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*>
genMaybe genName <*>
genMaybe genName
......
......@@ -44,6 +44,7 @@ def GetMinimalConfig():
"cluster": {
"master_node": "node1-uuid",
"ipolicy": None,
"default_iallocator_params": {},
"ndparams": {}
},
"instances": {},
......
......@@ -147,6 +147,9 @@ def UpgradeCluster(config_data):
ipolicy = cluster.setdefault("ipolicy", None)
if ipolicy:
UpgradeIPolicy(ipolicy, constants.IPOLICY_DEFAULTS, False)
ial_params = cluster.get("default_iallocator_params", None)
if not ial_params:
cluster["default_iallocator_params"] = {}
def UpgradeGroups(config_data):
......@@ -398,7 +401,12 @@ def UpgradeAll(config_data):
def DowngradeCluster(config_data):
DowngradeNdparams(config_data["cluster"])
cluster = config_data.get("cluster", None)
if not cluster:
raise Error("Cannot find the 'cluster' key in the configuration!")
DowngradeNdparams(cluster)
if "default_iallocator_params" in cluster:
del cluster["default_iallocator_params"]
def DowngradeGroups(config_data):
......
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