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__ = [ ...@@ -52,6 +52,7 @@ __all__ = [
"AUTO_PROMOTE_OPT", "AUTO_PROMOTE_OPT",
"AUTO_REPLACE_OPT", "AUTO_REPLACE_OPT",
"BACKEND_OPT", "BACKEND_OPT",
"BLK_OS_OPT",
"CLEANUP_OPT", "CLEANUP_OPT",
"CLUSTER_DOMAIN_SECRET_OPT", "CLUSTER_DOMAIN_SECRET_OPT",
"CONFIRM_OPT", "CONFIRM_OPT",
...@@ -73,6 +74,7 @@ __all__ = [ ...@@ -73,6 +74,7 @@ __all__ = [
"FORCE_OPT", "FORCE_OPT",
"FORCE_VARIANT_OPT", "FORCE_VARIANT_OPT",
"GLOBAL_FILEDIR_OPT", "GLOBAL_FILEDIR_OPT",
"HID_OS_OPT",
"HVLIST_OPT", "HVLIST_OPT",
"HVOPTS_OPT", "HVOPTS_OPT",
"HYPERVISOR_OPT", "HYPERVISOR_OPT",
...@@ -1029,6 +1031,15 @@ NODRBD_STORAGE_OPT = cli_option("--no-drbd-storage", dest="drbd_storage", ...@@ -1029,6 +1031,15 @@ NODRBD_STORAGE_OPT = cli_option("--no-drbd-storage", dest="drbd_storage",
action="store_false", default=True, action="store_false", default=True,
help="Disable support for DRBD") 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 #: Options provided by all commands
COMMON_OPTS = [DEBUG_OPT] COMMON_OPTS = [DEBUG_OPT]
......
...@@ -2625,6 +2625,16 @@ class LUSetClusterParams(LogicalUnit): ...@@ -2625,6 +2625,16 @@ class LUSetClusterParams(LogicalUnit):
("drbd_helper", None, _TOr(_TString, _TNone)), ("drbd_helper", None, _TOr(_TString, _TNone)),
("default_iallocator", None, _TMaybeString), ("default_iallocator", None, _TMaybeString),
("reserved_lvs", None, _TOr(_TListOf(_TNonEmptyString), _TNone)), ("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 REQ_BGL = False
...@@ -2898,6 +2908,30 @@ class LUSetClusterParams(LogicalUnit): ...@@ -2898,6 +2908,30 @@ class LUSetClusterParams(LogicalUnit):
if self.op.reserved_lvs is not None: if self.op.reserved_lvs is not None:
self.cluster.reserved_lvs = self.op.reserved_lvs 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) self.cfg.Update(self.cluster, feedback_fn)
......
...@@ -420,8 +420,9 @@ INISECT_BEP = "backend" ...@@ -420,8 +420,9 @@ INISECT_BEP = "backend"
INISECT_OSP = "os" INISECT_OSP = "os"
# dynamic device modification # dynamic device modification
DDM_ADD = 'add' DDM_ADD = "add"
DDM_REMOVE = 'remove' DDM_REMOVE = "remove"
DDMS_VALUES = frozenset([DDM_ADD, DDM_REMOVE])
# common exit codes # common exit codes
EXIT_SUCCESS = 0 EXIT_SUCCESS = 0
......
...@@ -315,6 +315,8 @@ class OpSetClusterParams(OpCode): ...@@ -315,6 +315,8 @@ class OpSetClusterParams(OpCode):
"remove_uids", "remove_uids",
"default_iallocator", "default_iallocator",
"reserved_lvs", "reserved_lvs",
"hidden_oss",
"blacklisted_oss",
] ]
......
...@@ -105,14 +105,30 @@ ...@@ -105,14 +105,30 @@
</cmdsynopsis> </cmdsynopsis>
<para> <para>
This command will allow you to modify OS parameters. At the moment This command will allow you to modify OS parameters.
we just support per-os-hypervisor settings. You can run modify
</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 <option>-H</option> with the same syntax as in
<command>gnt-cluster init</command> to override default hypervisor <command>gnt-cluster init</command> to override default hypervisor
parameters of the cluster for specified parameters of the cluster for specified
<replaceable>OS</replaceable> argument. <replaceable>OS</replaceable> argument.
</para> </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> <para>
Note: The <replaceable>OS</replaceable> doesn't have to exists. Note: The <replaceable>OS</replaceable> doesn't have to exists.
This allows preseeding the settings for This allows preseeding the settings for
......
...@@ -252,19 +252,31 @@ def ModifyOS(opts, args): ...@@ -252,19 +252,31 @@ def ModifyOS(opts, args):
else: else:
osp = None 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" ToStderr("At least one of OS parameters or hypervisor parameters"
" must be passed") " must be passed")
return 1 return 1
op = opcodes.OpSetClusterParams(vg_name=None, op = opcodes.OpSetClusterParams(os_hvp=os_hvp,
enabled_hypervisors=None, osparams=osp,
hvparams=None, hidden_oss=ohid,
beparams=None, blacklisted_oss=oblk)
nicparams=None,
candidate_pool_size=None,
os_hvp=os_hvp,
osparams=osp)
SubmitOpCode(op, opts=opts) SubmitOpCode(op, opts=opts)
return 0 return 0
...@@ -280,7 +292,8 @@ commands = { ...@@ -280,7 +292,8 @@ commands = {
ShowOSInfo, [ArgOs()], [], "", "Show detailed information about " ShowOSInfo, [ArgOs()], [], "", "Show detailed information about "
"operating systems"), "operating systems"),
'modify': ( '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"), "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