From 61a14bb3e714e2f410f0478a01d88541400d76f4 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 21 Sep 2010 09:59:33 +0200 Subject: [PATCH] Allow gnt-os modify to change the new OS params Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/cli.py | 11 +++++++++++ lib/cmdlib.py | 34 ++++++++++++++++++++++++++++++++++ lib/constants.py | 5 +++-- lib/opcodes.py | 2 ++ man/gnt-os.sgml | 20 ++++++++++++++++++-- scripts/gnt-os | 33 +++++++++++++++++++++++---------- 6 files changed, 91 insertions(+), 14 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 599a59fa9..2d4286339 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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] diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 0b3ab5453..e22e4e75f 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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) diff --git a/lib/constants.py b/lib/constants.py index ce4c6f1b1..17c9a2e19 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -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 diff --git a/lib/opcodes.py b/lib/opcodes.py index d1a8f7c09..f062f4fe8 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -315,6 +315,8 @@ class OpSetClusterParams(OpCode): "remove_uids", "default_iallocator", "reserved_lvs", + "hidden_oss", + "blacklisted_oss", ] diff --git a/man/gnt-os.sgml b/man/gnt-os.sgml index d4b698b74..4e7d5bc3e 100644 --- a/man/gnt-os.sgml +++ b/man/gnt-os.sgml @@ -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 diff --git a/scripts/gnt-os b/scripts/gnt-os index 6c419bd6c..59cae51d0 100755 --- a/scripts/gnt-os +++ b/scripts/gnt-os @@ -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"), } -- GitLab