"""
ht_kind = ssconf.SimpleStore().GetHypervisorType()
- if ht_kind == constants.HT_XEN30:
- cls = XenHypervisor
+ if ht_kind == constants.HT_XEN_PVM30:
+ cls = XenPvmHypervisor
elif ht_kind == constants.HT_FAKE:
cls = FakeHypervisor
else:
class XenHypervisor(BaseHypervisor):
- """Xen hypervisor interface"""
+ """Xen generic hypervisor interface
+
+ This is the Xen base class used for both Xen PVM and HVM. It contains
+ all the functionality that is identical for both.
+
+ """
@staticmethod
def _WriteConfigFile(instance, block_devices, extra_args):
- """Create a Xen 3.0 config file.
+ """A Xen instance config file.
"""
- 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)
- config.write("memory = %d\n" % instance.memory)
- config.write("vcpus = %d\n" % instance.vcpus)
- config.write("name = '%s'\n" % instance.name)
-
- vif_data = []
- for nic in instance.nics:
- nic_str = "mac=%s, bridge=%s" % (nic.mac, nic.bridge)
- ip = getattr(nic, "ip", None)
- if ip is not None:
- nic_str += ", ip=%s" % ip
- vif_data.append("'%s'" % nic_str)
-
- config.write("vif = [%s]\n" % ",".join(vif_data))
-
- disk_data = ["'phy:%s,%s,w'" % (rldev.dev_path, cfdev.iv_name)
- for cfdev, rldev in block_devices]
- config.write("disk = [%s]\n" % ",".join(disk_data))
-
- config.write("root = '/dev/sda ro'\n")
- config.write("on_poweroff = 'destroy'\n")
- config.write("on_reboot = 'restart'\n")
- config.write("on_crash = 'restart'\n")
- if extra_args:
- config.write("extra = '%s'\n" % extra_args)
- # just in case it exists
- utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
- f = open("/etc/xen/%s" % instance.name, "w")
- f.write(config.getvalue())
- f.close()
- return True
+ raise NotImplementedError
@staticmethod
def _RemoveConfigFile(instance):
"""Return a command for connecting to the console of an instance.
"""
- return "xm console %s" % instance.name
+ raise NotImplementedError
def Verify(self):
return "xend daemon is not running"
+class XenPvmHypervisor(XenHypervisor):
+ """Xen PVM hypervisor interface"""
+
+ @staticmethod
+ def _WriteConfigFile(instance, block_devices, extra_args):
+ """Create a Xen instance config file.
+
+ """
+ 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)
+ config.write("memory = %d\n" % instance.memory)
+ config.write("vcpus = %d\n" % instance.vcpus)
+ config.write("name = '%s'\n" % instance.name)
+
+ vif_data = []
+ for nic in instance.nics:
+ nic_str = "mac=%s, bridge=%s" % (nic.mac, nic.bridge)
+ ip = getattr(nic, "ip", None)
+ if ip is not None:
+ nic_str += ", ip=%s" % ip
+ vif_data.append("'%s'" % nic_str)
+
+ config.write("vif = [%s]\n" % ",".join(vif_data))
+
+ disk_data = ["'phy:%s,%s,w'" % (rldev.dev_path, cfdev.iv_name)
+ for cfdev, rldev in block_devices]
+ config.write("disk = [%s]\n" % ",".join(disk_data))
+
+ config.write("root = '/dev/sda ro'\n")
+ config.write("on_poweroff = 'destroy'\n")
+ config.write("on_reboot = 'restart'\n")
+ config.write("on_crash = 'restart'\n")
+ if extra_args:
+ config.write("extra = '%s'\n" % extra_args)
+ # just in case it exists
+ utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
+ f = open("/etc/xen/%s" % instance.name, "w")
+ f.write(config.getvalue())
+ f.close()
+ return True
+
+ @staticmethod
+ def GetShellCommandForConsole(instance):
+ """Return a command for connecting to the console of an instance.
+
+ """
+ return "xm console %s" % instance.name
+
+
class FakeHypervisor(BaseHypervisor):
"""Fake hypervisor interface.