diff --git a/lib/hypervisor.py b/lib/hypervisor.py index 534114c7178cff96ebbbe37a8f2c4eed82782925..d3b7e870933ac22bf923a79851d082db706d1f76 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)