Commit eb247ad5 authored by Jose A. Lopes's avatar Jose A. Lopes

Add 'enabled_user_shutdown' cluster field

... including object, queries, opcode, LU, command line, upgrade, etc.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent f623c4ef
......@@ -552,15 +552,21 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
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):
hv_state=None, disk_state=None, enabled_disk_templates=None,
enabled_user_shutdown=False):
"""Initialise the cluster.
@type candidate_pool_size: int
@param candidate_pool_size: master candidate pool size
@type enabled_disk_templates: list of string
@param enabled_disk_templates: list of disk_templates to be used in this
cluster
@type enabled_user_shutdown: bool
@param enabled_user_shutdown: whether user shutdown is enabled cluster
wide
"""
# TODO: complete the docstring
if config.ConfigWriter.IsCluster():
......@@ -819,6 +825,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
disk_state_static=disk_state,
enabled_disk_templates=enabled_disk_templates,
candidate_certs=candidate_certs,
enabled_user_shutdown=enabled_user_shutdown,
)
master_node_config = objects.Node(name=hostname.name,
primary_ip=hostname.ip,
......
......@@ -83,6 +83,7 @@ __all__ = [
"EARLY_RELEASE_OPT",
"ENABLED_HV_OPT",
"ENABLED_DISK_TEMPLATES_OPT",
"ENABLED_USER_SHUTDOWN_OPT",
"ERROR_CODES_OPT",
"FAILURE_ONLY_OPT",
"FIELDS_OPT",
......@@ -1273,6 +1274,12 @@ ENABLED_DISK_TEMPLATES_OPT = cli_option("--enabled-disk-templates",
"disk templates",
type="string", default=None)
ENABLED_USER_SHUTDOWN_OPT = cli_option("--user-shutdown",
default=None,
dest="enabled_user_shutdown",
help="Whether user shutdown is enabled",
type="bool")
NIC_PARAMS_OPT = cli_option("-N", "--nic-parameters", dest="nicparams",
type="keyval", default={},
help="NIC parameters")
......
......@@ -265,6 +265,12 @@ def InitCluster(opts, args):
hv_state = dict(opts.hv_state)
default_ialloc_params = opts.default_iallocator_params
if opts.enabled_user_shutdown:
enabled_user_shutdown = True
else:
enabled_user_shutdown = False
bootstrap.InitCluster(cluster_name=args[0],
secondary_ip=opts.secondary_ip,
vg_name=vg_name,
......@@ -295,6 +301,7 @@ def InitCluster(opts, args):
hv_state=hv_state,
disk_state=disk_state,
enabled_disk_templates=enabled_disk_templates,
enabled_user_shutdown=enabled_user_shutdown,
)
op = opcodes.OpClusterPostInit()
SubmitOpCode(op, opts=opts)
......@@ -540,6 +547,7 @@ def ShowClusterConfig(opts, args):
utils.CommaJoin(pathutils.ES_SEARCH_PATH)),
("enabled disk templates",
utils.CommaJoin(result["enabled_disk_templates"])),
("enabled user shutdown", result["enabled_user_shutdown"]),
]),
("Default node parameters",
......@@ -1115,7 +1123,8 @@ def SetClusterParams(opts, args):
opts.ipolicy_spindle_ratio is not None or
opts.modify_etc_hosts is not None or
opts.file_storage_dir is not None or
opts.shared_file_storage_dir is not None):
opts.shared_file_storage_dir is not None or
opts.enabled_user_shutdown is not None):
ToStderr("Please give at least one of the parameters.")
return 1
......@@ -1227,6 +1236,7 @@ def SetClusterParams(opts, args):
force=opts.force,
file_storage_dir=opts.file_storage_dir,
shared_file_storage_dir=opts.shared_file_storage_dir,
enabled_user_shutdown=opts.enabled_user_shutdown,
)
SubmitOrSend(op, opts)
return 0
......@@ -2109,7 +2119,8 @@ commands = {
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, GLOBAL_GLUSTER_FILEDIR_OPT]
ENABLED_USER_SHUTDOWN_OPT, IPOLICY_STD_SPECS_OPT,
GLOBAL_GLUSTER_FILEDIR_OPT]
+ INSTANCE_POLICY_OPTS + SPLIT_ISPECS_OPTS,
"[opts...] <cluster_name>", "Initialises a new cluster configuration"),
"destroy": (
......@@ -2192,7 +2203,8 @@ commands = {
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] +
[ENABLED_DISK_TEMPLATES_OPT, IPOLICY_STD_SPECS_OPT, MODIFY_ETCHOSTS_OPT,
ENABLED_USER_SHUTDOWN_OPT] +
INSTANCE_POLICY_OPTS + [GLOBAL_FILEDIR_OPT, GLOBAL_SHARED_FILEDIR_OPT],
"[opts...]",
"Alters the parameters of the cluster"),
......
......@@ -434,6 +434,7 @@ class LUClusterQuery(NoHooksLU):
"hidden_os": cluster.hidden_os,
"blacklisted_os": cluster.blacklisted_os,
"enabled_disk_templates": cluster.enabled_disk_templates,
"enabled_user_shutdown": cluster.enabled_user_shutdown,
}
return result
......@@ -1396,6 +1397,9 @@ class LUClusterSetParams(LogicalUnit):
if self.op.use_external_mip_script is not None:
self.cluster.use_external_mip_script = self.op.use_external_mip_script
if self.op.enabled_user_shutdown is not None:
self.cluster.enabled_user_shutdown = self.op.enabled_user_shutdown
def helper_os(aname, mods, desc):
desc += " OS list"
lst = getattr(self.cluster, aname)
......
......@@ -1592,6 +1592,7 @@ class Cluster(TaggableObject):
"enabled_disk_templates",
"candidate_certs",
"max_running_jobs",
"enabled_user_shutdown",
] + _TIMESTAMPS + _UUID
def UpgradeConfig(self):
......@@ -1724,6 +1725,9 @@ class Cluster(TaggableObject):
if self.max_running_jobs is None:
self.max_running_jobs = constants.LUXID_MAXIMAL_RUNNING_JOBS_DEFAULT
if self.enabled_user_shutdown is None:
self.enabled_user_shutdown = False
@property
def primary_hypervisor(self):
"""The first hypervisor is the primary.
......
......@@ -708,6 +708,7 @@ $(buildObject "Cluster" "cluster" $
, simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
, simpleField "candidate_certs" [t| CandidateCertificates |]
, simpleField "max_running_jobs" [t| Int |]
, simpleField "enabled_user_shutdown" [t| Bool |]
]
++ timeStampFields
++ uuidFields
......
......@@ -236,6 +236,7 @@ $(genOpCode "OpCode"
, pClusterFileStorageDir
, pClusterSharedFileStorageDir
, pClusterGlusterStorageDir
, pEnabledUserShutdown
],
[])
, ("OpClusterRedistConf",
......
......@@ -260,6 +260,7 @@ module Ganeti.OpParams
, pReason
, pSequential
, pEnabledDiskTemplates
, pEnabledUserShutdown
, pAdminStateSource
) where
......@@ -745,6 +746,12 @@ pEnabledDiskTemplates =
optionalField $
simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
pEnabledUserShutdown :: Field
pEnabledUserShutdown =
withDoc "Whether user shutdown is enabled cluster wide" .
optionalField $
simpleField "enabled_user_shutdown" [t| Bool |]
pQueryWhat :: Field
pQueryWhat =
withDoc "Resource(s) to query for" $
......
......@@ -165,6 +165,8 @@ handleCall _ _ cdata QueryClusterInfo =
, ("hidden_os", showJSON $ clusterHiddenOs cluster)
, ("blacklisted_os", showJSON $ clusterBlacklistedOs cluster)
, ("enabled_disk_templates", showJSON diskTemplates)
, ("enabled_user_shutdown",
showJSON $ clusterEnabledUserShutdown cluster)
]
in case master of
......
......@@ -183,7 +183,7 @@ instance Arbitrary OpCodes.OpCode where
emptyMUD <*> emptyMUD <*> arbitrary <*>
arbitrary <*> emptyMUD <*> arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> genMaybe genName <*> genMaybe genName
arbitrary <*> genMaybe genName <*> genMaybe genName <*> arbitrary
"OP_CLUSTER_REDIST_CONF" -> pure OpCodes.OpClusterRedistConf
"OP_CLUSTER_ACTIVATE_MASTER_IP" ->
pure OpCodes.OpClusterActivateMasterIp
......
......@@ -47,6 +47,7 @@ def GetMinimalConfig():
"default_iallocator_params": {},
"ndparams": {},
"candidate_certs": {},
"enabled_user_shutdown": False,
},
"instances": {},
"networks": {},
......
......@@ -670,6 +670,7 @@ class TestInstanceQuery(unittest.TestCase):
query.IQ_CONSOLE, query.IQ_NODES, query.IQ_NETWORKS]))
cluster = objects.Cluster(cluster_name="testcluster",
enabled_user_shutdown=True,
hvparams=constants.HVC_DEFAULTS,
beparams={
constants.PP_DEFAULT: constants.BEC_DEFAULTS,
......
......@@ -151,6 +151,8 @@ def UpgradeCluster(config_data):
if not ial_params:
cluster["default_iallocator_params"] = {}
cluster["candidate_certs"] = cluster.get("candidate_certs", {})
if "enabled_user_shutdown" not in cluster:
cluster["enabled_user_shutdown"] = False
def UpgradeGroups(config_data):
......@@ -423,6 +425,8 @@ def DowngradeCluster(config_data):
del cluster[param]
if "max_running_jobs" in cluster:
del cluster["max_running_jobs"]
if "enabled_user_shutdown" in cluster:
del cluster["enabled_user_shutdown"]
DowngradeInstances(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