]>
git.ipfire.org Git - oddments/fireinfo.git/blob - fireinfo/hypervisor.py
9286bd48ab863f92775dac26d400926bd0701886
2 ###############################################################################
5 # Copyright (C) 2010, 2011 IPFire Team (www.ipfire.org) #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 class Hypervisor(object):
27 self
.__info
= _fireinfo
.get_hypervisor()
32 Return the current instance of the System class.
34 We need to do that as a property because otherwise
37 return system
.System()
42 Returns the name of the hypervisor vendor.
47 # Some of the hypervisors can be detected in a right way.
48 # We can return them at this place.
49 if self
.__info
["hypervisor"] in ("Xen", "VMWare", "KVM"):
50 return self
.__info
["hypervisor"]
52 # Citrix Xen says it is Microsoft Hv.
53 if self
.__info
["hypervisor"] == "Microsoft" and \
54 self
.system
.bios_vendor
== "Xen":
57 if not self
.__info
["hypervisor"]:
58 # On VMWare systems, the bios vendor string contains "VMWare".
59 if self
.__is
_hypervisor
_vmware
():
62 # VirtualBox got "innotek GmbH" as bios vendor.
63 elif self
.__is
_hypervisor
_virtualbox
():
67 elif self
.__is
_hypervisor
_qemu
():
70 # Check for Microsoft.
71 elif self
.__is
_hypervisor
_microsoft
():
79 Returns if the host is running in full virt mode or
80 if it is running in a paravirtualized environment.
85 if self
.__info
["virtype"]:
86 return self
.__info
["virtype"]
88 if self
.vendor
in ("Qemu", "KVM", "VirtualBox", "VMWare"):
96 Returns true if the host is running in a virtual environment.
99 return _fireinfo
.is_virtualized() or \
100 "hypervisor" in self
.system
.cpu
.flags
or \
101 self
.__is
_hypervisor
_virtualbox
() or \
102 self
.__is
_hypervisor
_vmware
() or \
103 self
.__is
_hypervisor
_qemu
() or \
104 self
.__is
_hypervisor
_microsoft
()
106 def __is_hypervisor_virtualbox(self
):
108 Check for virtualbox hypervisor by comparing the bios vendor string
111 return self
.system
.bios_vendor
== "innotek GmbH"
113 def __is_hypervisor_vmware(self
):
115 Check for the VMWare hypervisor by the VMWare Hypervisor port check.
117 http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458
119 if self
.system
.vendor
:
120 return self
.system
.vendor
.startswith("VMware")
122 # XXX We should use _fireinfo.vmware_hypervisor_port_check() here, too.
123 # This currently segfaults (and I have no clue why) on VMware player.
125 def __is_hypervisor_qemu(self
):
127 Check for old qemu emulator.
129 return self
.system
.bios_vendor
== "Bochs"
131 def __is_hypervisor_microsoft(self
):
133 Check for Microsoft hypervisor.
135 return "Microsoft" in self
.system
.vendor
138 if __name__
== "__main__":
141 print "Vendor:", h
.vendor
142 print "Type:", h
.type
143 print "Virtual:", h
.virtual