Allow gnt-os modify to change the new OS params
authorIustin Pop <iustin@google.com>
Tue, 21 Sep 2010 07:59:33 +0000 (09:59 +0200)
committerIustin Pop <iustin@google.com>
Thu, 30 Sep 2010 00:10:25 +0000 (20:10 -0400)
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/cli.py
lib/cmdlib.py
lib/constants.py
lib/opcodes.py
man/gnt-os.sgml
scripts/gnt-os

index 599a59f..2d42863 100644 (file)
@@ -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]
 
index 0b3ab54..e22e4e7 100644 (file)
@@ -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)
 
 
index ce4c6f1..17c9a2e 100644 (file)
@@ -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
index d1a8f7c..f062f4f 100644 (file)
@@ -315,6 +315,8 @@ class OpSetClusterParams(OpCode):
     "remove_uids",
     "default_iallocator",
     "reserved_lvs",
+    "hidden_oss",
+    "blacklisted_oss",
     ]
 
 
index d4b698b..4e7d5bc 100644 (file)
     </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
     </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
       <replaceable>OS</replaceable>es not yet known to
index 6c419bd..59cae51 100755 (executable)
@@ -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"),
   }