Commit bdd55f71 authored by Iustin Pop's avatar Iustin Pop
Browse files

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
parent bcf043c9
......@@ -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)
......
......@@ -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):
......
......@@ -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 = {
......
......@@ -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 = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment