"""
-from ganeti import ssconf
from ganeti import constants
from ganeti import errors
from ganeti.hypervisor import hv_fake
from ganeti.hypervisor import hv_xen
+from ganeti.hypervisor import hv_kvm
-def GetHypervisor():
- """Return a Hypervisor instance.
+_HYPERVISOR_MAP = {
+ constants.HT_XEN_PVM: hv_xen.XenPvmHypervisor,
+ constants.HT_XEN_HVM: hv_xen.XenHvmHypervisor,
+ constants.HT_FAKE: hv_fake.FakeHypervisor,
+ constants.HT_KVM: hv_kvm.KVMHypervisor,
+ }
+
+
+def GetHypervisorClass(ht_kind):
+ """Return a Hypervisor class.
+
+ This function returns the hypervisor class corresponding to the
+ given hypervisor name.
- This function parses the cluster hypervisor configuration file and
- instantiates a class based on the value of this file.
+ @type ht_kind: string
+ @param ht_kind: The requested hypervisor type
"""
- ht_kind = ssconf.SimpleStore().GetHypervisorType()
- if ht_kind == constants.HT_XEN_PVM30:
- cls = hv_xen.XenPvmHypervisor
- elif ht_kind == constants.HT_XEN_HVM31:
- cls = hv_xen.XenHvmHypervisor
- elif ht_kind == constants.HT_FAKE:
- cls = hv_fake.FakeHypervisor
- else:
+ if ht_kind not in _HYPERVISOR_MAP:
raise errors.HypervisorError("Unknown hypervisor type '%s'" % ht_kind)
+
+ cls = _HYPERVISOR_MAP[ht_kind]
+ return cls
+
+
+def GetHypervisor(ht_kind):
+ """Return a Hypervisor instance.
+
+ This is a wrapper over L{GetHypervisorClass} which returns an
+ instance of the class.
+
+ @type ht_kind: string
+ @param ht_kind: The requested hypervisor type
+
+ """
+ cls = GetHypervisorClass(ht_kind)
+
return cls()