Skip to content
Snippets Groups Projects
Commit 631eb662 authored by Alexander Schreiber's avatar Alexander Schreiber
Browse files

Use a generic Xen hypervisor interface.

Abstract the parts of the Xen hypervisor interface shared by both PVM and
HVM into a generic interface, subclass the special case PVM from that.

Prepatch for adding HVM support.


Reviewed-by: iustinp
parent 9c233417
No related branches found
No related tags found
No related merge requests found
......@@ -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])
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment