Statistics
| Branch: | Tag: | Revision:

root / lib / hypervisor / __init__.py @ 5023934a

History | View | Annotate | Download (1.5 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 ssconf
27 65a6f9b7 Michael Hanselmann
from ganeti import constants
28 65a6f9b7 Michael Hanselmann
from ganeti import errors
29 65a6f9b7 Michael Hanselmann
30 a2d32034 Michael Hanselmann
from ganeti.hypervisor import hv_fake
31 a2d32034 Michael Hanselmann
from ganeti.hypervisor import hv_xen
32 65a6f9b7 Michael Hanselmann
33 65a6f9b7 Michael Hanselmann
34 a9369c6e Michael Hanselmann
_HYPERVISOR_MAP = {
35 a9369c6e Michael Hanselmann
    constants.HT_XEN_PVM30: hv_xen.XenPvmHypervisor,
36 a9369c6e Michael Hanselmann
    constants.HT_XEN_HVM31: hv_xen.XenHvmHypervisor,
37 a9369c6e Michael Hanselmann
    constants.HT_FAKE: hv_fake.FakeHypervisor,
38 a9369c6e Michael Hanselmann
    }
39 a9369c6e Michael Hanselmann
40 a9369c6e Michael Hanselmann
41 65a6f9b7 Michael Hanselmann
def GetHypervisor():
42 65a6f9b7 Michael Hanselmann
  """Return a Hypervisor instance.
43 65a6f9b7 Michael Hanselmann

44 65a6f9b7 Michael Hanselmann
  This function parses the cluster hypervisor configuration file and
45 65a6f9b7 Michael Hanselmann
  instantiates a class based on the value of this file.
46 65a6f9b7 Michael Hanselmann

47 65a6f9b7 Michael Hanselmann
  """
48 65a6f9b7 Michael Hanselmann
  ht_kind = ssconf.SimpleStore().GetHypervisorType()
49 a9369c6e Michael Hanselmann
50 a9369c6e Michael Hanselmann
  if ht_kind not in _HYPERVISOR_MAP:
51 65a6f9b7 Michael Hanselmann
    raise errors.HypervisorError("Unknown hypervisor type '%s'" % ht_kind)
52 a9369c6e Michael Hanselmann
53 a9369c6e Michael Hanselmann
  cls = _HYPERVISOR_MAP[ht_kind]
54 65a6f9b7 Michael Hanselmann
  return cls()