]> git.ipfire.org Git - oddments/fireinfo.git/blob - fireinfo/hypervisor.py
Check if bios vendor is "innotek GmbH" to get if the system is virtualized.
[oddments/fireinfo.git] / fireinfo / hypervisor.py
1 #!/usr/bin/python
2
3 import _fireinfo
4 import system
5
6 class Hypervisor(object):
7 def __init__(self):
8 self.__info = _fireinfo.get_hypervisor()
9
10 @property
11 def system(self):
12 """
13 Return the current instance of the System class.
14
15 We need to do that as a property because otherwise
16 we get a recursion.
17 """
18 return system.System()
19
20 @property
21 def vendor(self):
22 """
23 Returns the name of the hypervisor vendor.
24 """
25 if not self.virtual:
26 return None
27
28 # Some of the hypervisors can be detected in a right way.
29 # We can return them at this place.
30 if self.__info["hypervisor"] in ("Xen", "VMWare", "KVM"):
31 return self.__info["hypervisor"]
32
33 # Citrix Xen says it is Microsoft Hv.
34 if self.__info["hypervisor"] == "Microsoft" and \
35 self.system.bios_vendor == "Xen":
36 return "Xen"
37
38 if not self.__info["hypervisor"]:
39 # On VMWare systems, the bios vendor string contains "VMWare".
40 if "VMWare" in self.system.bios_vendor:
41 return "VMWare"
42
43 # VirtualBox got "innotek GmbH" as bios vendor.
44 elif self.system.bios_vendor == "innotek GmbH":
45 return "VirtualBox"
46
47 return "unknown"
48
49 @property
50 def type(self):
51 """
52 Returns if the host is running in full virt mode or
53 if it is running in a paravirtualized environment.
54 """
55 if not self.virtual:
56 return None
57
58 return self.__info["virtype"]
59
60 @property
61 def virtual(self):
62 """
63 Returns true if the host is running in a virtual environment.
64 Otherwise: false.
65 """
66 return _fireinfo.is_virtualized() or \
67 "hypervisor" in self.system.cpu.flags or \
68 self.system.bios_vendor == "innotek GmbH"
69
70
71 if __name__ == "__main__":
72 h = Hypervisor()
73
74 print "Vendor:", h.vendor
75 print "Type:", h.type
76 print "Virtual:", h.virtual