diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 298fc3882ea4cf9b4fef3bde0b85258f5e278c2f..6f1778e524eec4356b773c053b31d741647fad3c 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -4101,7 +4101,11 @@ class LUSetInstanceParms(LogicalUnit): self.ip = getattr(self.op, "ip", None) self.mac = getattr(self.op, "mac", None) self.bridge = getattr(self.op, "bridge", None) - if [self.mem, self.vcpus, self.ip, self.bridge, self.mac].count(None) == 5: + self.kernel_path = getattr(self.op, "kernel_path", None) + self.initrd_path = getattr(self.op, "initrd_path", None) + all_parms = [self.mem, self.vcpus, self.ip, self.bridge, self.mac, + self.kernel_path, self.initrd_path] + if all_parms.count(None) == len(all_parms): raise errors.OpPrereqError("No changes submitted") if self.mem is not None: try: @@ -4130,6 +4134,24 @@ class LUSetInstanceParms(LogicalUnit): if not utils.IsValidMac(self.mac): raise errors.OpPrereqError('Invalid MAC address %s' % self.mac) + if self.kernel_path is not None: + self.do_kernel_path = True + if self.kernel_path == constants.VALUE_NONE: + raise errors.OpPrereqError("Can't set instance to no kernel") + + if self.kernel_path != constants.VALUE_DEFAULT: + if not os.path.isabs(self.kernel_path): + raise errors.OpPrereError("The kernel path must be an absolute" + " filename") + + if self.initrd_path is not None: + self.do_initrd_path = True + if self.initrd_path not in (constants.VALUE_NONE, + constants.VALUE_DEFAULT): + if not os.path.isabs(self.kernel_path): + raise errors.OpPrereError("The initrd path must be an absolute" + " filename") + instance = self.cfg.GetInstanceInfo( self.cfg.ExpandInstanceName(self.op.instance_name)) if instance is None: @@ -4161,6 +4183,12 @@ class LUSetInstanceParms(LogicalUnit): if self.mac: instance.nics[0].mac = self.mac result.append(("mac", self.mac)) + if self.do_kernel_path: + instance.kernel_path = self.kernel_path + result.append(("kernel_path", self.kernel_path)) + if self.do_initrd_path: + instance.initrd_path = self.initrd_path + result.append(("initrd_path", self.initrd_path)) self.cfg.AddInstance(instance) diff --git a/lib/constants.py b/lib/constants.py index 6caae1757dedf023ed97276c5db7cf4643747f12..47db98e5e6a797e79ca6e981620604e915403448 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -60,6 +60,9 @@ EXPORT_CONF_FILE = "config.ini" XEN_KERNEL = _autoconf.XEN_KERNEL XEN_INITRD = _autoconf.XEN_INITRD +VALUE_DEFAULT = "default" +VALUE_NONE = "none" + # hooks-related constants HOOKS_BASE_DIR = _autoconf.SYSCONFDIR + "/ganeti/hooks" HOOKS_PHASE_PRE = "pre" diff --git a/lib/opcodes.py b/lib/opcodes.py index e44a731a579be0639e2eabac8f904ed97b2bc775..c28423b9f62b7c334af35f792f6a9fa4ae5de8d8 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -260,7 +260,10 @@ class OpQueryInstanceData(OpCode): class OpSetInstanceParms(OpCode): """Change the parameters of an instance.""" OP_ID = "OP_INSTANCE_SET_PARMS" - __slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge", "mac"] + __slots__ = [ + "instance_name", "mem", "vcpus", "ip", "bridge", "mac", + "kernel_path", "initrd_path", + ] # OS opcodes diff --git a/scripts/gnt-instance b/scripts/gnt-instance index 07285f09ced0c38b62eb352a55e3ebcf5b44fe88..602c9846da7ed943ffe98d4b07d9f918fd400531 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -134,6 +134,29 @@ def _ConfirmOperation(inames, text): return choice +def _TransformPath(user_input): + """Transform a user path into a canonical value. + + This function transforms the a path passed as textual information + into the constants that the LU code expects. + + """ + if user_input: + if user_input.lower() == "default": + result_path = constants.VALUE_DEFAULT + elif user_input.lower() == "none": + result_path = constants.VALUE_NONE + else: + if not os.path.isabs(user_input): + raise errors.OpPrereqError("Path '%s' is not an absolute filename" % + user_input) + result_path = user_input + else: + result_path = constants.VALUE_DEFAULT + + return result_path + + def ListInstances(opts, args): """List instances and their properties. @@ -627,13 +650,19 @@ def SetInstanceParms(opts, args): mac - the new MAC address of the instance """ - if not (opts.mem or opts.vcpus or opts.ip or opts.bridge or opts.mac): + if not (opts.mem or opts.vcpus or opts.ip or opts.bridge or opts.mac or + opts.kernel_path or opts.initrd_path): logger.ToStdout("Please give at least one of the parameters.") return 1 + kernel_path = _TransformPath(opts.kernel_path) + initrd_path = _TransformPath(opts.initrd_path) + op = opcodes.OpSetInstanceParms(instance_name=args[0], mem=opts.mem, vcpus=opts.vcpus, ip=opts.ip, - bridge=opts.bridge, mac=opts.mac) + bridge=opts.bridge, mac=opts.mac, + kernel_path=opts.kernel_path, + initrd_path=opts.initrd_path) result = SubmitOpCode(op) if result: @@ -815,6 +844,14 @@ commands = { make_option("--mac", dest="mac", help="MAC address", default=None, type="string", metavar="<MACADDRESS>"), + make_option("--kernel", dest="kernel_path", + help="Path to the instances' kernel (or" + " 'default')", default=None, + type="string", metavar="<FILENAME>"), + make_option("--initrd", dest="initrd_path", + help="Path to the instances' initrd (or 'none', or" + " 'default')", default=None, + type="string", metavar="<FILENAME>"), ], "<instance>", "Alters the parameters of an instance"), 'shutdown': (ShutdownInstance, ARGS_ANY,