commit bdd55f717237ce80b54deb09aad39a143d1aaa41
Author: Iustin Pop <iustin@google.com>
Date:   Wed Sep 19 13:52:34 2007 +0000

    Allow 'add instance' to not start the new instance
    
    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

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index d742fc6..d3f583c 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -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",
-              "wait_for_sync"]
+              "wait_for_sync", "ip_check"]
 
   def BuildHooksEnv(self):
     """Build hooks env.
@@ -2862,11 +2862,16 @@ class LUCreateInstance(LogicalUnit):
       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)
diff --git a/lib/opcodes.py b/lib/opcodes.py
index d5b06ad..94a68fa 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -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",
-               "wait_for_sync"]
+               "wait_for_sync", "ip_check"]
 
 
 class OpReinstallInstance(OpCode):
diff --git a/scripts/gnt-backup b/scripts/gnt-backup
index 6a86770..c6512e5 100755
--- a/scripts/gnt-backup
+++ b/scripts/gnt-backup
@@ -131,6 +131,9 @@ import_opts = [
               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 = {
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index 1b05aa9..243a4b3 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -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,
-                                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
@@ -602,7 +603,13 @@ add_opts = [
               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 = {
