From 03abdbe86f931cbd6a9bb3d1bb896f23aa19a753 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 8 Jan 2008 11:04:06 +0000 Subject: [PATCH] Change the Xen PVM to use the new kernel options This patch changes the hypervisor to use the new kernel and initrd instance attributes. They kernel is handled as expected (use the custom or the default one), but the initrd is treated a little bit special, in order to keep compatibility with previous behaviour: - if customized and not found, raise an error - if default and not found, do not use one Reviewed-by: imsnah --- lib/hypervisor.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/hypervisor.py b/lib/hypervisor.py index 534114c71..d3b7e8709 100644 --- a/lib/hypervisor.py +++ b/lib/hypervisor.py @@ -136,7 +136,7 @@ class XenHypervisor(BaseHypervisor): @staticmethod def _WriteConfigFile(instance, block_devices, extra_args): - """A Xen instance config file. + """Write the Xen config file for the instance. """ raise NotImplementedError @@ -316,14 +316,42 @@ class XenPvmHypervisor(XenHypervisor): @staticmethod def _WriteConfigFile(instance, block_devices, extra_args): - """Create a Xen instance config file. + """Write the Xen config file for the instance. """ config = StringIO() config.write("# this is autogenerated by Ganeti, please do not edit\n#\n") - config.write("kernel = '%s'\n" % constants.XEN_KERNEL) - if os.path.exists(constants.XEN_INITRD): - config.write("ramdisk = '%s'\n" % constants.XEN_INITRD) + + # kernel handling + if instance.kernel_path in (None, constants.VALUE_DEFAULT): + kpath = constants.XEN_KERNEL + else: + if not os.path.exists(instance.kernel_path): + raise errors.HypervisorError("The kernel %s for instance %s is" + " missing" % (instance.kernel_path, + instance.name)) + kpath = instance.kernel_path + config.write("kernel = '%s'\n" % kpath) + + # initrd handling + if instance.initrd_path in (None, constants.VALUE_DEFAULT): + if os.path.exists(constants.XEN_INITRD): + initrd_path = constants.XEN_INITRD + else: + initrd_path = None + elif instance.initrd_path == constants.VALUE_NONE: + initrd_path = None + else: + if not os.path.exists(instance.initrd_path): + raise errors.HypervisorError("The initrd %s for instance %s is" + " missing" % (instance.initrd_path, + instance.name)) + initrd_path = instance.initrd_path + + if initrd_path: + config.write("ramdisk = '%s'\n" % initrd_path) + + # rest of the settings config.write("memory = %d\n" % instance.memory) config.write("vcpus = %d\n" % instance.vcpus) config.write("name = '%s'\n" % instance.name) -- GitLab