Allow 'add instance' to not start the new instance
authorIustin Pop <iustin@google.com>
Wed, 19 Sep 2007 13:52:34 +0000 (13:52 +0000)
committerIustin Pop <iustin@google.com>
Wed, 19 Sep 2007 13:52:34 +0000 (13:52 +0000)
This patch allows 'gnt-instance add' to not start the newly-created
instance. It also allow 'gnt-instance add' and 'gnt-backup import' to
not check for IP conflicts (only when not starting the instance).

Reviewed-by: ultrotter

lib/cmdlib.py
lib/opcodes.py
scripts/gnt-backup
scripts/gnt-instance

index d742fc6..d3f583c 100644 (file)
@@ -2694,7 +2694,7 @@ class LUCreateInstance(LogicalUnit):
   HTYPE = constants.HTYPE_INSTANCE
   _OP_REQP = ["instance_name", "mem_size", "disk_size", "pnode",
               "disk_template", "swap_size", "mode", "start", "vcpus",
   HTYPE = constants.HTYPE_INSTANCE
   _OP_REQP = ["instance_name", "mem_size", "disk_size", "pnode",
               "disk_template", "swap_size", "mode", "start", "vcpus",
-              "wait_for_sync"]
+              "wait_for_sync", "ip_check"]
 
   def BuildHooksEnv(self):
     """Build hooks env.
 
   def BuildHooksEnv(self):
     """Build hooks env.
@@ -2862,11 +2862,16 @@ class LUCreateInstance(LogicalUnit):
       inst_ip = ip
     self.inst_ip = inst_ip
 
       inst_ip = ip
     self.inst_ip = inst_ip
 
-    command = ["fping", "-q", hostname1.ip]
-    result = utils.RunCmd(command)
-    if not result.failed:
-      raise errors.OpPrereqError("IP %s of instance %s already in use" %
-                                 (hostname1.ip, instance_name))
+    if self.op.start and not self.op.ip_check:
+      raise errors.OpPrereqError("Cannot ignore IP address conflicts when"
+                                 " adding an instance in start mode")
+
+    if self.op.ip_check:
+      command = ["fping", "-q", hostname1.ip]
+      result = utils.RunCmd(command)
+      if not result.failed:
+        raise errors.OpPrereqError("IP address %s of instance %s already"
+                                   " in use" % (hostname1.ip, instance_name))
 
     # bridge verification
     bridge = getattr(self.op, "bridge", None)
 
     # bridge verification
     bridge = getattr(self.op, "bridge", None)
index d5b06ad..94a68fa 100644 (file)
@@ -138,7 +138,7 @@ class OpCreateInstance(OpCode):
   __slots__ = ["instance_name", "mem_size", "disk_size", "os_type", "pnode",
                "disk_template", "snode", "swap_size", "mode",
                "vcpus", "ip", "bridge", "src_node", "src_path", "start",
   __slots__ = ["instance_name", "mem_size", "disk_size", "os_type", "pnode",
                "disk_template", "snode", "swap_size", "mode",
                "vcpus", "ip", "bridge", "src_node", "src_path", "start",
-               "wait_for_sync"]
+               "wait_for_sync", "ip_check"]
 
 
 class OpReinstallInstance(OpCode):
 
 
 class OpReinstallInstance(OpCode):
index 6a86770..c6512e5 100755 (executable)
@@ -131,6 +131,9 @@ import_opts = [
               metavar="<node>"),
   make_option("--src-dir", dest="src_dir", help="Source directory",
               metavar="<dir>"),
               metavar="<node>"),
   make_option("--src-dir", dest="src_dir", help="Source directory",
               metavar="<dir>"),
+  make_option("--no-ip-check", dest="ip_check", default=True,
+              action="store_false", help="Don't check that the instance's IP"
+              " is alive"),
   ]
 
 commands = {
   ]
 
 commands = {
index 1b05aa9..243a4b3 100755 (executable)
@@ -187,7 +187,8 @@ def AddInstance(opts, args):
                                 mode=constants.INSTANCE_CREATE,
                                 os_type=opts.os, pnode=opts.node,
                                 snode=opts.snode, vcpus=opts.vcpus,
                                 mode=constants.INSTANCE_CREATE,
                                 os_type=opts.os, pnode=opts.node,
                                 snode=opts.snode, vcpus=opts.vcpus,
-                                ip=opts.ip, bridge=opts.bridge, start=True,
+                                ip=opts.ip, bridge=opts.bridge,
+                                start=opts.start, ip_check=opts.ip_check,
                                 wait_for_sync=opts.wait_for_sync)
   SubmitOpCode(op)
   return 0
                                 wait_for_sync=opts.wait_for_sync)
   SubmitOpCode(op)
   return 0
@@ -602,7 +603,13 @@ add_opts = [
               metavar="<node>"),
   make_option("-b", "--bridge", dest="bridge",
               help="Bridge to connect this instance to",
               metavar="<node>"),
   make_option("-b", "--bridge", dest="bridge",
               help="Bridge to connect this instance to",
-              default=None, metavar="<bridge>")
+              default=None, metavar="<bridge>"),
+  make_option("--no-start", dest="start", default=True,
+              action="store_false", help="Don't start the instance after"
+              " creation"),
+  make_option("--no-ip-check", dest="ip_check", default=True,
+              action="store_false", help="Don't check that the instance's IP"
+              " is alive (only valid with --no-start)"),
   ]
 
 commands = {
   ]
 
 commands = {