root / lib / hypervisor / __init__.py @ d1908b41
History | View | Annotate | Download (1.6 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 | 65a6f9b7 | Michael Hanselmann | |
33 | 65a6f9b7 | Michael Hanselmann | |
34 | a9369c6e | Michael Hanselmann | _HYPERVISOR_MAP = { |
35 | 00cd937c | Iustin Pop | constants.HT_XEN_PVM: hv_xen.XenPvmHypervisor, |
36 | 00cd937c | Iustin Pop | constants.HT_XEN_HVM: hv_xen.XenHvmHypervisor, |
37 | a9369c6e | Michael Hanselmann | constants.HT_FAKE: hv_fake.FakeHypervisor, |
38 | eb58f9b1 | Guido Trotter | constants.HT_KVM: hv_kvm.KVMHypervisor, |
39 | a9369c6e | Michael Hanselmann | } |
40 | a9369c6e | Michael Hanselmann | |
41 | a9369c6e | Michael Hanselmann | |
42 | e69d05fd | Iustin Pop | def GetHypervisor(ht_kind): |
43 | 65a6f9b7 | Michael Hanselmann | """Return a Hypervisor instance.
|
44 | 65a6f9b7 | Michael Hanselmann |
|
45 | 65a6f9b7 | Michael Hanselmann | This function parses the cluster hypervisor configuration file and
|
46 | 65a6f9b7 | Michael Hanselmann | instantiates a class based on the value of this file.
|
47 | 65a6f9b7 | Michael Hanselmann |
|
48 | e69d05fd | Iustin Pop | @type ht_kind: string
|
49 | e69d05fd | Iustin Pop | @param ht_kind: The requested hypervisor type
|
50 | 3707f851 | Michael Hanselmann |
|
51 | 65a6f9b7 | Michael Hanselmann | """
|
52 | a9369c6e | Michael Hanselmann | if ht_kind not in _HYPERVISOR_MAP: |
53 | 65a6f9b7 | Michael Hanselmann | raise errors.HypervisorError("Unknown hypervisor type '%s'" % ht_kind) |
54 | a9369c6e | Michael Hanselmann | |
55 | a9369c6e | Michael Hanselmann | cls = _HYPERVISOR_MAP[ht_kind] |
56 | 65a6f9b7 | Michael Hanselmann | return cls() |