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:
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:
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)
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"
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
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.
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:
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,