Allow OS changes without reinstallation
authorIustin Pop <iustin@google.com>
Wed, 17 Mar 2010 13:33:44 +0000 (14:33 +0100)
committerIustin Pop <iustin@google.com>
Wed, 17 Mar 2010 14:10:45 +0000 (15:10 +0100)
This patch modifies LUSetInstanceParms to allow OS name changes, without
reinstallation, in case an OS gets renamed on-disk.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/cmdlib.py
lib/opcodes.py
man/gnt-instance.sgml
scripts/gnt-instance

index 40e0a29..7b4e9ae 100644 (file)
@@ -7744,9 +7744,13 @@ class LUSetInstanceParams(LogicalUnit):
       self.op.disk_template = None
     if not hasattr(self.op, "remote_node"):
       self.op.remote_node = None
+    if not hasattr(self.op, "os_name"):
+      self.op.os_name = None
+    if not hasattr(self.op, "force_variant"):
+      self.op.force_variant = False
     self.op.force = getattr(self.op, "force", False)
     if not (self.op.nics or self.op.disks or self.op.disk_template or
-            self.op.hvparams or self.op.beparams):
+            self.op.hvparams or self.op.beparams or self.op.os_name):
       raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL)
 
     if self.op.hvparams:
@@ -8174,6 +8178,11 @@ class LUSetInstanceParams(LogicalUnit):
                                      (disk_op, len(instance.disks)),
                                      errors.ECODE_INVAL)
 
+    # OS change
+    if self.op.os_name and not self.op.force:
+      _CheckNodeHasOS(self, instance.primary_node, self.op.os_name,
+                      self.op.force_variant)
+
     return
 
   def _ConvertPlainToDrbd(self, feedback_fn):
@@ -8384,6 +8393,10 @@ class LUSetInstanceParams(LogicalUnit):
       for key, val in self.op.beparams.iteritems():
         result.append(("be/%s" % key, val))
 
+    # OS change
+    if self.op.os_name:
+      instance.os = self.op.os_name
+
     self.cfg.Update(instance, feedback_fn)
 
     return result
index d7d3c55..f979ad0 100644 (file)
@@ -621,7 +621,7 @@ class OpSetInstanceParams(OpCode):
     "instance_name",
     "hvparams", "beparams", "force",
     "nics", "disks", "disk_template",
-    "remote_node",
+    "remote_node", "os_name", "force_variant",
     ]
 
 
index b8ed14b..0e53802 100644 (file)
@@ -1403,6 +1403,8 @@ instance5: 11225
               <arg>drbd</arg>
             </group></arg>
 
+          <sbr>
+            <arg>--os-name=<replaceable>OS</replaceable> <arg>--force-variant</arg></arg>
 
           <sbr>
           <arg>--submit</arg>
@@ -1454,6 +1456,16 @@ instance5: 11225
         </para>
 
         <para>
+          The option <option>--os-name</option> will change the OS
+          name for the instance (without reinstallation). In case an
+          OS variant is specified that is not found, then by default
+          the modification is refused,
+          unless <option>--force-variant</option> is passed. An
+          invalid OS will also be refused, unless
+          the <option>--force</option> option is given.
+        </para>
+
+        <para>
           The <option>--submit</option> option is used to send the job to
           the master daemon but not wait for its completion. The job
           ID will be shown so that it can be examined via
index 45444f1..fb17f7c 100755 (executable)
@@ -1208,7 +1208,7 @@ def SetInstanceParams(opts, args):
 
   """
   if not (opts.nics or opts.disks or opts.disk_template or
-          opts.hvparams or opts.beparams):
+          opts.hvparams or opts.beparams or opts.os):
     ToStderr("Please give at least one of the parameters.")
     return 1
 
@@ -1261,6 +1261,8 @@ def SetInstanceParams(opts, args):
                                    remote_node=opts.node,
                                    hvparams=opts.hvparams,
                                    beparams=opts.beparams,
+                                   os_name=opts.os,
+                                   force_variant=opts.force_variant,
                                    force=opts.force)
 
   # even if here we process the result, we allow submit only
@@ -1417,7 +1419,7 @@ commands = {
   'modify': (
     SetInstanceParams, ARGS_ONE_INSTANCE,
     [BACKEND_OPT, DISK_OPT, FORCE_OPT, HVOPTS_OPT, NET_OPT, SUBMIT_OPT,
-     DISK_TEMPLATE_OPT, SINGLE_NODE_OPT],
+     DISK_TEMPLATE_OPT, SINGLE_NODE_OPT, OS_OPT, FORCE_VARIANT_OPT],
     "<instance>", "Alters the parameters of an instance"),
   'shutdown': (
     GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()],