diff --git a/lib/constants.py b/lib/constants.py index 5dfba2b48e72118ba99ae6d62b9941364d6f3f22..365472f83e5ed029d0f77c32d6dc07d024cf5fbc 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -149,7 +149,7 @@ INSTANCE_REBOOT_HARD = "hard" INSTANCE_REBOOT_FULL = "full" # Hypervisor constants -HT_XEN30 = "xen-3.0" +HT_XEN_PVM30 = "xen-3.0" HT_FAKE = "fake" -HYPER_TYPES = frozenset([HT_XEN30, HT_FAKE]) +HYPER_TYPES = frozenset([HT_XEN_PVM30, HT_FAKE]) diff --git a/lib/hypervisor.py b/lib/hypervisor.py index e2683c67d4d7620c572a7393468cb792c8df9aa4..4ba701920931a153e563169af1454345ff8b792f 100644 --- a/lib/hypervisor.py +++ b/lib/hypervisor.py @@ -42,8 +42,8 @@ def GetHypervisor(): """ 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: @@ -124,48 +124,19 @@ class BaseHypervisor(object): 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): @@ -324,7 +295,7 @@ class XenHypervisor(BaseHypervisor): """Return a command for connecting to the console of an instance. """ - return "xm console %s" % instance.name + raise NotImplementedError def Verify(self): @@ -337,6 +308,58 @@ class XenHypervisor(BaseHypervisor): 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.