Commit 61a14bb3 authored by Iustin Pop's avatar Iustin Pop

Allow gnt-os modify to change the new OS params

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent cd14c16c
......@@ -52,6 +52,7 @@ __all__ = [
"AUTO_PROMOTE_OPT",
"AUTO_REPLACE_OPT",
"BACKEND_OPT",
"BLK_OS_OPT",
"CLEANUP_OPT",
"CLUSTER_DOMAIN_SECRET_OPT",
"CONFIRM_OPT",
......@@ -73,6 +74,7 @@ __all__ = [
"FORCE_OPT",
"FORCE_VARIANT_OPT",
"GLOBAL_FILEDIR_OPT",
"HID_OS_OPT",
"HVLIST_OPT",
"HVOPTS_OPT",
"HYPERVISOR_OPT",
......@@ -1029,6 +1031,15 @@ NODRBD_STORAGE_OPT = cli_option("--no-drbd-storage", dest="drbd_storage",
action="store_false", default=True,
help="Disable support for DRBD")
HID_OS_OPT = cli_option("--hidden", dest="hidden",
type="bool", default=None, metavar=_YORNO,
help="Sets the hidden flag on the OS")
BLK_OS_OPT = cli_option("--blacklisted", dest="blacklisted",
type="bool", default=None, metavar=_YORNO,
help="Sets the blacklisted flag on the OS")
#: Options provided by all commands
COMMON_OPTS = [DEBUG_OPT]
......
......@@ -2625,6 +2625,16 @@ class LUSetClusterParams(LogicalUnit):
("drbd_helper", None, _TOr(_TString, _TNone)),
("default_iallocator", None, _TMaybeString),
("reserved_lvs", None, _TOr(_TListOf(_TNonEmptyString), _TNone)),
("hidden_oss", None, _TOr(_TListOf(\
_TAnd(_TList,
_TIsLength(2),
_TMap(lambda v: v[0], _TElemOf(constants.DDMS_VALUES)))),
_TNone)),
("blacklisted_oss", None, _TOr(_TListOf(\
_TAnd(_TList,
_TIsLength(2),
_TMap(lambda v: v[0], _TElemOf(constants.DDMS_VALUES)))),
_TNone)),
]
REQ_BGL = False
......@@ -2898,6 +2908,30 @@ class LUSetClusterParams(LogicalUnit):
if self.op.reserved_lvs is not None:
self.cluster.reserved_lvs = self.op.reserved_lvs
def helper_oss(aname, mods, desc):
lst = getattr(self.cluster, aname)
for key, val in mods:
if key == constants.DDM_ADD:
if val in lst:
feedback_fn("OS %s already in %s, ignoring", val, desc)
else:
lst.append(val)
elif key == constants.DDM_REMOVE:
if val in lst:
lst.remove(val)
else:
feedback_fn("OS %s not found in %s, ignoring", val, desc)
else:
raise errors.ProgrammerError("Invalid modification '%s'" % key)
if self.op.hidden_oss:
helper_oss("hidden_oss", self.op.hidden_oss,
"hidden OS list")
if self.op.blacklisted_oss:
helper_oss("blacklisted_oss", self.op.blacklisted_oss,
"blacklisted OS list")
self.cfg.Update(self.cluster, feedback_fn)
......
......@@ -420,8 +420,9 @@ INISECT_BEP = "backend"
INISECT_OSP = "os"
# dynamic device modification
DDM_ADD = 'add'
DDM_REMOVE = 'remove'
DDM_ADD = "add"
DDM_REMOVE = "remove"
DDMS_VALUES = frozenset([DDM_ADD, DDM_REMOVE])
# common exit codes
EXIT_SUCCESS = 0
......
......@@ -315,6 +315,8 @@ class OpSetClusterParams(OpCode):
"remove_uids",
"default_iallocator",
"reserved_lvs",
"hidden_oss",
"blacklisted_oss",
]
......
......@@ -105,14 +105,30 @@
</cmdsynopsis>
<para>
This command will allow you to modify OS parameters. At the moment
we just support per-os-hypervisor settings. You can run modify
This command will allow you to modify OS parameters.
</para>
<para>
To modify the per-OS hypervisor parameters (which override the
global hypervisor parameters), you can run modify
<option>-H</option> with the same syntax as in
<command>gnt-cluster init</command> to override default hypervisor
parameters of the cluster for specified
<replaceable>OS</replaceable> argument.
</para>
<para>
To modify the hidden and blacklisted states of an OS, pass the
options <option>--hidden <replaceable>yes|no</replaceable></option>,
or respectively <option>--blacklisted ...</option>. The 'hidden'
state means that an OS won't be listed by default in the OS
list, but is available for installation. The 'blacklisted' state
means that the OS is not listed and is also not allowed for new
instance creations (but can be used for reinstalling old
instances).
</para>
<para>
Note: The <replaceable>OS</replaceable> doesn't have to exists.
This allows preseeding the settings for
......
......@@ -252,19 +252,31 @@ def ModifyOS(opts, args):
else:
osp = None
if not (os_hvp or osp):
if opts.hidden is not None:
if opts.hidden:
ohid = [(constants.DDM_ADD, os)]
else:
ohid = [(constants.DDM_REMOVE, os)]
else:
ohid = None
if opts.blacklisted is not None:
if opts.blacklisted:
oblk = [(constants.DDM_ADD, os)]
else:
oblk = [(constants.DDM_REMOVE, os)]
else:
oblk = None
if not (os_hvp or osp or ohid or oblk):
ToStderr("At least one of OS parameters or hypervisor parameters"
" must be passed")
return 1
op = opcodes.OpSetClusterParams(vg_name=None,
enabled_hypervisors=None,
hvparams=None,
beparams=None,
nicparams=None,
candidate_pool_size=None,
os_hvp=os_hvp,
osparams=osp)
op = opcodes.OpSetClusterParams(os_hvp=os_hvp,
osparams=osp,
hidden_oss=ohid,
blacklisted_oss=oblk)
SubmitOpCode(op, opts=opts)
return 0
......@@ -280,7 +292,8 @@ commands = {
ShowOSInfo, [ArgOs()], [], "", "Show detailed information about "
"operating systems"),
'modify': (
ModifyOS, ARGS_ONE_OS, [HVLIST_OPT, OSPARAMS_OPT, DRY_RUN_OPT], "",
ModifyOS, ARGS_ONE_OS, [HVLIST_OPT, OSPARAMS_OPT, DRY_RUN_OPT,
HID_OS_OPT, BLK_OS_OPT], "",
"Modify the OS parameters"),
}
......
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