Commit fdad8c4d authored by Balazs Lecz's avatar Balazs Lecz
Browse files

Add --add-uids/--remove-uids to gnt-cluster modify


Signed-off-by: default avatarBalazs Lecz <leczb@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 1338f2b4
......@@ -44,6 +44,7 @@ from optparse import (OptionParser, TitledHelpFormatter,
__all__ = [
# Command line options
"ADD_UIDS_OPT",
"ALLOCATABLE_OPT",
"ALL_OPT",
"AUTO_PROMOTE_OPT",
......@@ -111,6 +112,7 @@ __all__ = [
"RAPI_CERT_OPT",
"READD_OPT",
"REBOOT_TYPE_OPT",
"REMOVE_UIDS_OPT",
"SECONDARY_IP_OPT",
"SELECT_OS_OPT",
"SEP_OPT",
......@@ -935,6 +937,18 @@ UIDPOOL_OPT = cli_option("--uid-pool", default=None,
help=("A list of user-ids or user-id"
" ranges separated by commas"))
ADD_UIDS_OPT = cli_option("--add-uids", default=None,
action="store", dest="add_uids",
help=("A list of user-ids or user-id"
" ranges separated by commas, to be"
" added to the user-id pool"))
REMOVE_UIDS_OPT = cli_option("--remove-uids", default=None,
action="store", dest="remove_uids",
help=("A list of user-ids or user-id"
" ranges separated by commas, to be"
" removed from the user-id pool"))
def _ParseArgs(argv, commands, aliases):
"""Parser for the command line arguments.
......
......@@ -2272,6 +2272,12 @@ class LUSetClusterParams(LogicalUnit):
if self.op.uid_pool:
uidpool.CheckUidPool(self.op.uid_pool)
if self.op.add_uids:
uidpool.CheckUidPool(self.op.add_uids)
if self.op.remove_uids:
uidpool.CheckUidPool(self.op.remove_uids)
def ExpandNames(self):
# FIXME: in the future maybe other cluster params won't require checking on
# all nodes to be modified.
......@@ -2466,6 +2472,12 @@ class LUSetClusterParams(LogicalUnit):
if self.op.maintain_node_health is not None:
self.cluster.maintain_node_health = self.op.maintain_node_health
if self.op.add_uids is not None:
uidpool.AddToUidPool(self.cluster.uid_pool, self.op.add_uids)
if self.op.remove_uids is not None:
uidpool.RemoveFromUidPool(self.cluster.uid_pool, self.op.remove_uids)
if self.op.uid_pool is not None:
self.cluster.uid_pool = self.op.uid_pool
......
......@@ -307,6 +307,8 @@ class OpSetClusterParams(OpCode):
"candidate_pool_size",
"maintain_node_health",
"uid_pool",
"add_uids",
"remove_uids",
]
......
......@@ -78,6 +78,36 @@ def ParseUidPool(value, separator=None):
return ranges
def AddToUidPool(uid_pool, add_uids):
"""Add a list of user-ids/user-id ranges to a user-id pool.
@param uid_pool: a user-id pool (list of integer tuples)
@param add_uids: user-id ranges to be added to the pool
(list of integer tuples)
"""
for uid_range in add_uids:
if uid_range not in uid_pool:
uid_pool.append(uid_range)
uid_pool.sort()
def RemoveFromUidPool(uid_pool, remove_uids):
"""Remove a list of user-ids/user-id ranges from a user-id pool.
@param uid_pool: a user-id pool (list of integer tuples)
@param remove_uids: user-id ranges to be removed from the pool
(list of integer tuples)
"""
for uid_range in remove_uids:
if uid_range not in uid_pool:
raise errors.OpPrereqError(
"User-id range to be removed is not found in the current"
" user-id pool: %s" % uid_range, errors.ECODE_INVAL)
uid_pool.remove(uid_range)
def CheckUidPool(uid_pool):
"""Sanity check user-id pool range definition values.
......
......@@ -603,7 +603,9 @@ def SetClusterParams(opts, args):
opts.beparams or opts.nicparams or
opts.candidate_pool_size is not None or
opts.uid_pool is not None or
opts.maintain_node_health is not None):
opts.maintain_node_health is not None or
opts.add_uids is not None or
opts.remove_uids is not None):
ToStderr("Please give at least one of the parameters.")
return 1
......@@ -637,6 +639,14 @@ def SetClusterParams(opts, args):
if uid_pool is not None:
uid_pool = uidpool.ParseUidPool(uid_pool)
add_uids = opts.add_uids
if add_uids is not None:
add_uids = uidpool.ParseUidPool(add_uids)
remove_uids = opts.remove_uids
if remove_uids is not None:
remove_uids = uidpool.ParseUidPool(remove_uids)
op = opcodes.OpSetClusterParams(vg_name=vg_name,
enabled_hypervisors=hvlist,
hvparams=hvparams,
......@@ -645,7 +655,9 @@ def SetClusterParams(opts, args):
nicparams=nicparams,
candidate_pool_size=opts.candidate_pool_size,
maintain_node_health=mnh,
uid_pool=uid_pool)
uid_pool=uid_pool,
add_uids=add_uids,
remove_uids=remove_uids)
SubmitOpCode(op, opts=opts)
return 0
......@@ -797,7 +809,7 @@ commands = {
SetClusterParams, ARGS_NONE,
[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],
UIDPOOL_OPT, ADD_UIDS_OPT, REMOVE_UIDS_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