Statistics
| Branch: | Tag: | Revision:

root / lib / hypervisor / __init__.py @ fe5b0c42

History | View | Annotate | Download (1.9 kB)

1 65a6f9b7 Michael Hanselmann
#
2 65a6f9b7 Michael Hanselmann
#
3 65a6f9b7 Michael Hanselmann
4 65a6f9b7 Michael Hanselmann
# Copyright (C) 2006, 2007, 2008 Google Inc.
5 65a6f9b7 Michael Hanselmann
#
6 65a6f9b7 Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 65a6f9b7 Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 65a6f9b7 Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 65a6f9b7 Michael Hanselmann
# (at your option) any later version.
10 65a6f9b7 Michael Hanselmann
#
11 65a6f9b7 Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 65a6f9b7 Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 65a6f9b7 Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 65a6f9b7 Michael Hanselmann
# General Public License for more details.
15 65a6f9b7 Michael Hanselmann
#
16 65a6f9b7 Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 65a6f9b7 Michael Hanselmann
# along with this program; if not, write to the Free Software
18 65a6f9b7 Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 65a6f9b7 Michael Hanselmann
# 02110-1301, USA.
20 65a6f9b7 Michael Hanselmann
21 65a6f9b7 Michael Hanselmann
22 65a6f9b7 Michael Hanselmann
"""Virtualization interface abstraction
23 65a6f9b7 Michael Hanselmann

24 65a6f9b7 Michael Hanselmann
"""
25 65a6f9b7 Michael Hanselmann
26 65a6f9b7 Michael Hanselmann
from ganeti import constants
27 65a6f9b7 Michael Hanselmann
from ganeti import errors
28 65a6f9b7 Michael Hanselmann
29 a2d32034 Michael Hanselmann
from ganeti.hypervisor import hv_fake
30 a2d32034 Michael Hanselmann
from ganeti.hypervisor import hv_xen
31 eb58f9b1 Guido Trotter
from ganeti.hypervisor import hv_kvm
32 48297fa2 Iustin Pop
from ganeti.hypervisor import hv_chroot
33 65a6f9b7 Michael Hanselmann
34 65a6f9b7 Michael Hanselmann
35 a9369c6e Michael Hanselmann
_HYPERVISOR_MAP = {
36 48297fa2 Iustin Pop
  constants.HT_XEN_PVM: hv_xen.XenPvmHypervisor,
37 48297fa2 Iustin Pop
  constants.HT_XEN_HVM: hv_xen.XenHvmHypervisor,
38 48297fa2 Iustin Pop
  constants.HT_FAKE: hv_fake.FakeHypervisor,
39 48297fa2 Iustin Pop
  constants.HT_KVM: hv_kvm.KVMHypervisor,
40 48297fa2 Iustin Pop
  constants.HT_CHROOT: hv_chroot.ChrootManager,
41 48297fa2 Iustin Pop
  }
42 a9369c6e Michael Hanselmann
43 a9369c6e Michael Hanselmann
44 e5a45a16 Iustin Pop
def GetHypervisorClass(ht_kind):
45 e5a45a16 Iustin Pop
  """Return a Hypervisor class.
46 65a6f9b7 Michael Hanselmann

47 e5a45a16 Iustin Pop
  This function returns the hypervisor class corresponding to the
48 e5a45a16 Iustin Pop
  given hypervisor name.
49 65a6f9b7 Michael Hanselmann

50 e69d05fd Iustin Pop
  @type ht_kind: string
51 e69d05fd Iustin Pop
  @param ht_kind: The requested hypervisor type
52 3707f851 Michael Hanselmann

53 65a6f9b7 Michael Hanselmann
  """
54 a9369c6e Michael Hanselmann
  if ht_kind not in _HYPERVISOR_MAP:
55 65a6f9b7 Michael Hanselmann
    raise errors.HypervisorError("Unknown hypervisor type '%s'" % ht_kind)
56 a9369c6e Michael Hanselmann
57 a9369c6e Michael Hanselmann
  cls = _HYPERVISOR_MAP[ht_kind]
58 e5a45a16 Iustin Pop
  return cls
59 e5a45a16 Iustin Pop
60 e5a45a16 Iustin Pop
61 e5a45a16 Iustin Pop
def GetHypervisor(ht_kind):
62 e5a45a16 Iustin Pop
  """Return a Hypervisor instance.
63 e5a45a16 Iustin Pop

64 e5a45a16 Iustin Pop
  This is a wrapper over L{GetHypervisorClass} which returns an
65 e5a45a16 Iustin Pop
  instance of the class.
66 e5a45a16 Iustin Pop

67 e5a45a16 Iustin Pop
  @type ht_kind: string
68 e5a45a16 Iustin Pop
  @param ht_kind: The requested hypervisor type
69 e5a45a16 Iustin Pop

70 e5a45a16 Iustin Pop
  """
71 e5a45a16 Iustin Pop
  cls = GetHypervisorClass(ht_kind)
72 e5a45a16 Iustin Pop
73 65a6f9b7 Michael Hanselmann
  return cls()