root / lib / hypervisor / __init__.py @ d3ce528b
History | View | Annotate | Download (2 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 | 4b5e40a5 | Iustin Pop | from ganeti.hypervisor import hv_lxc |
34 | 65a6f9b7 | Michael Hanselmann | |
35 | 65a6f9b7 | Michael Hanselmann | |
36 | a9369c6e | Michael Hanselmann | _HYPERVISOR_MAP = { |
37 | 48297fa2 | Iustin Pop | constants.HT_XEN_PVM: hv_xen.XenPvmHypervisor, |
38 | 48297fa2 | Iustin Pop | constants.HT_XEN_HVM: hv_xen.XenHvmHypervisor, |
39 | 48297fa2 | Iustin Pop | constants.HT_FAKE: hv_fake.FakeHypervisor, |
40 | 48297fa2 | Iustin Pop | constants.HT_KVM: hv_kvm.KVMHypervisor, |
41 | 48297fa2 | Iustin Pop | constants.HT_CHROOT: hv_chroot.ChrootManager, |
42 | 4b5e40a5 | Iustin Pop | constants.HT_LXC: hv_lxc.LXCHypervisor, |
43 | 48297fa2 | Iustin Pop | } |
44 | a9369c6e | Michael Hanselmann | |
45 | a9369c6e | Michael Hanselmann | |
46 | e5a45a16 | Iustin Pop | def GetHypervisorClass(ht_kind): |
47 | e5a45a16 | Iustin Pop | """Return a Hypervisor class.
|
48 | 65a6f9b7 | Michael Hanselmann |
|
49 | e5a45a16 | Iustin Pop | This function returns the hypervisor class corresponding to the
|
50 | e5a45a16 | Iustin Pop | given hypervisor name.
|
51 | 65a6f9b7 | Michael Hanselmann |
|
52 | e69d05fd | Iustin Pop | @type ht_kind: string
|
53 | e69d05fd | Iustin Pop | @param ht_kind: The requested hypervisor type
|
54 | 3707f851 | Michael Hanselmann |
|
55 | 65a6f9b7 | Michael Hanselmann | """
|
56 | a9369c6e | Michael Hanselmann | if ht_kind not in _HYPERVISOR_MAP: |
57 | 65a6f9b7 | Michael Hanselmann | raise errors.HypervisorError("Unknown hypervisor type '%s'" % ht_kind) |
58 | a9369c6e | Michael Hanselmann | |
59 | a9369c6e | Michael Hanselmann | cls = _HYPERVISOR_MAP[ht_kind] |
60 | e5a45a16 | Iustin Pop | return cls
|
61 | e5a45a16 | Iustin Pop | |
62 | e5a45a16 | Iustin Pop | |
63 | e5a45a16 | Iustin Pop | def GetHypervisor(ht_kind): |
64 | e5a45a16 | Iustin Pop | """Return a Hypervisor instance.
|
65 | e5a45a16 | Iustin Pop |
|
66 | e5a45a16 | Iustin Pop | This is a wrapper over L{GetHypervisorClass} which returns an
|
67 | e5a45a16 | Iustin Pop | instance of the class.
|
68 | e5a45a16 | Iustin Pop |
|
69 | e5a45a16 | Iustin Pop | @type ht_kind: string
|
70 | e5a45a16 | Iustin Pop | @param ht_kind: The requested hypervisor type
|
71 | e5a45a16 | Iustin Pop |
|
72 | e5a45a16 | Iustin Pop | """
|
73 | e5a45a16 | Iustin Pop | cls = GetHypervisorClass(ht_kind) |
74 | e5a45a16 | Iustin Pop | |
75 | 65a6f9b7 | Michael Hanselmann | return cls() |