From bdd55f717237ce80b54deb09aad39a143d1aaa41 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 19 Sep 2007 13:52:34 +0000 Subject: [PATCH] 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 --- lib/cmdlib.py | 17 +++++++++++------ lib/opcodes.py | 2 +- scripts/gnt-backup | 3 +++ scripts/gnt-instance | 11 +++++++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index d742fc6eb..d3f583c8f 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 d5b06ada7..94a68fa24 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 6a86770df..c6512e517 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 1b05aa986..243a4b398 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 = { -- GitLab