For the xen-hvm hypervisor, the KERNEL_PATH parameter is needed but
today is hardcoded to a constants in the xen hypervisor library (argh!).

This patch moves this to a hypervisor constant with the default value
being the current hardcoded path. This will allow cluster/instance
customisation based on the installed xen version.

This should fix Debian bug #528618.

Signed-off-by: Iustin Pop <ius...@google.com>
Reviewed-by: Guido Trotter <ultrot...@google.com>
(cherry picked from commit e2ee1cea7709a2ef82153ec808c4fc3a5bce3ea1)
---
 lib/constants.py         |    1 +
 lib/hypervisor/hv_xen.py |   18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/lib/constants.py b/lib/constants.py
index 9dcb5f3..46b5191 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -510,6 +510,7 @@ HVC_DEFAULTS = {
     HV_VNC_BIND_ADDRESS: '0.0.0.0',
     HV_ACPI: True,
     HV_PAE: True,
+    HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
     },
   HT_KVM: {
     HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 76a8df1..dc17199 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -518,6 +518,7 @@ class XenHvmHypervisor(XenHypervisor):
     constants.HV_NIC_TYPE,
     constants.HV_PAE,
     constants.HV_VNC_BIND_ADDRESS,
+    constants.HV_KERNEL_PATH,
     ]
 
   @classmethod
@@ -559,6 +560,12 @@ class XenHvmHypervisor(XenHypervisor):
                                    " be an absolute path or None, not %s" %
                                    iso_path)
 
+    if not hvparams[constants.HV_KERNEL_PATH]:
+      raise errors.HypervisorError("Need a kernel for the instance")
+
+    if not os.path.isabs(hvparams[constants.HV_KERNEL_PATH]):
+      raise errors.HypervisorError("The kernel path must be an absolute path")
+
   def ValidateParameters(self, hvparams):
     """Check the given parameters for validity.
 
@@ -580,6 +587,11 @@ class XenHvmHypervisor(XenHypervisor):
                                    " an existing regular file, not %s" %
                                    iso_path)
 
+    kernel_path = hvparams[constants.HV_KERNEL_PATH]
+    if not os.path.isfile(kernel_path):
+      raise errors.HypervisorError("Instance kernel '%s' not found or"
+                                   " not a file" % kernel_path)
+
   @classmethod
   def _WriteConfigFile(cls, instance, block_devices):
     """Create a Xen 3.1 HVM config file.
@@ -589,7 +601,11 @@ class XenHvmHypervisor(XenHypervisor):
 
     config = StringIO()
     config.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
-    config.write("kernel = '/usr/lib/xen/boot/hvmloader'\n")
+
+    # kernel handling
+    kpath = hvp[constants.HV_KERNEL_PATH]
+    config.write("kernel = '%s'\n" % kpath)
+
     config.write("builder = 'hvm'\n")
     config.write("memory = %d\n" % instance.beparams[constants.BE_MEMORY])
     config.write("vcpus = %d\n" % instance.beparams[constants.BE_VCPUS])
-- 
1.6.3.3

Reply via email to