From 25a8792cb981df1979ce383248499ed207d203a4 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 17 Mar 2010 15:00:14 +0100 Subject: [PATCH] Instance creation: implement --no-install mode This is a simple patch that adds the no-install mode for instance creation, allowing import from foreign source of the actual OS (instead of requiring the preparation of data in a form expected by the import scripts). Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/cli.py | 11 ++++++++++- lib/cmdlib.py | 21 +++++++++++++++------ lib/opcodes.py | 3 ++- man/gnt-instance.sgml | 9 ++++++++- scripts/gnt-instance | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 2e0a23c7e..bd717d328 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -88,6 +88,7 @@ __all__ = [ "NODE_PLACEMENT_OPT", "NOHDR_OPT", "NOIPCHECK_OPT", + "NO_INSTALL_OPT", "NONAMECHECK_OPT", "NOLVM_STORAGE_OPT", "NOMODIFY_ETCHOSTS_OPT", @@ -591,6 +592,11 @@ FORCE_VARIANT_OPT = cli_option("--force-variant", dest="force_variant", action="store_true", default=False, help="Force an unknown variant") +NO_INSTALL_OPT = cli_option("--no-install", dest="no_install", + action="store_true", default=False, + help="Do not install the OS (will" + " enable no-start)") + BACKEND_OPT = cli_option("-B", "--backend-parameters", dest="beparams", type="keyval", default={}, help="Backend parameters") @@ -1553,11 +1559,13 @@ def GenericInstanceCreate(mode, opts, args): os_type = opts.os src_node = None src_path = None + no_install = opts.no_install elif mode == constants.INSTANCE_IMPORT: start = False os_type = None src_node = opts.src_node src_path = opts.src_dir + no_install = None else: raise errors.ProgrammerError("Invalid creation mode %s" % mode) @@ -1579,7 +1587,8 @@ def GenericInstanceCreate(mode, opts, args): start=start, os_type=os_type, src_node=src_node, - src_path=src_path) + src_path=src_path, + no_install=no_install) SubmitOrSend(op, opts) return 0 diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 7b4e9ae57..80e8a7b23 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -5826,6 +5826,11 @@ class LUCreateInstance(LogicalUnit): # for tools if not hasattr(self.op, "name_check"): self.op.name_check = True + if not hasattr(self.op, "no_install"): + self.op.no_install = False + if self.op.no_install and self.op.start: + self.LogInfo("No-installation mode selected, disabling startup") + self.op.start = False # validate/normalize the instance name self.op.instance_name = utils.HostInfo.NormalizeName(self.op.instance_name) if self.op.ip_check and not self.op.name_check: @@ -6070,6 +6075,9 @@ class LUCreateInstance(LogicalUnit): # works again! self.op.force_variant = True + if self.op.no_install: + self.LogInfo("No-installation mode has no effect during import") + else: # INSTANCE_CREATE if getattr(self.op, "os_type", None) is None: raise errors.OpPrereqError("No guest OS specified", @@ -6441,12 +6449,13 @@ class LUCreateInstance(LogicalUnit): if iobj.disk_template != constants.DT_DISKLESS and not self.adopt_disks: if self.op.mode == constants.INSTANCE_CREATE: - feedback_fn("* running the instance OS create scripts...") - # FIXME: pass debug option from opcode to backend - result = self.rpc.call_instance_os_add(pnode_name, iobj, False, - self.op.debug_level) - result.Raise("Could not add os for instance %s" - " on node %s" % (instance, pnode_name)) + if not self.op.no_install: + feedback_fn("* running the instance OS create scripts...") + # FIXME: pass debug option from opcode to backend + result = self.rpc.call_instance_os_add(pnode_name, iobj, False, + self.op.debug_level) + result.Raise("Could not add os for instance %s" + " on node %s" % (instance, pnode_name)) elif self.op.mode == constants.INSTANCE_IMPORT: feedback_fn("* running the instance OS import scripts...") diff --git a/lib/opcodes.py b/lib/opcodes.py index f979ad0f3..a20687612 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -460,7 +460,8 @@ class OpCreateInstance(OpCode): OP_ID = "OP_INSTANCE_CREATE" OP_DSC_FIELD = "instance_name" __slots__ = [ - "instance_name", "os_type", "force_variant", + "instance_name", + "os_type", "force_variant", "no_install", "pnode", "disk_template", "snode", "mode", "disks", "nics", "src_node", "src_path", "start", diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml index 0e5380271..178a3596f 100644 --- a/man/gnt-instance.sgml +++ b/man/gnt-instance.sgml @@ -85,6 +85,7 @@ <arg>--no-ip-check</arg> <arg>--no-name-check</arg> <arg>--no-start</arg> + <arg>--no-install</arg> <sbr> <group> <arg rep="repeat">--net=<replaceable>N</replaceable><arg rep="repeat">:options</arg></arg> @@ -243,7 +244,13 @@ <para> The <option>-o</option> options specifies the operating system to be installed. The available operating systems can - be listed with <command>gnt-os list</command>. + be listed with <command>gnt-os + list</command>. Passing <option>--no-install</option> will + however skip the OS installation, allowing a manual import + if so desired. Note that the no-installation mode will + automatically disable the start-up of the instance (without + an OS, it most likely won't be able to start-up + successfully). </para> <para> diff --git a/scripts/gnt-instance b/scripts/gnt-instance index fb17f7c04..406325348 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -1341,6 +1341,7 @@ add_opts = [ NWSYNC_OPT, OS_OPT, FORCE_VARIANT_OPT, + NO_INSTALL_OPT, OS_SIZE_OPT, SUBMIT_OPT, ] -- GitLab