2
Network introspection utilities using ioctl and the /proc filesystem.
7
def get_vm_info(root_path="/"):
9
This is a utility that returns the virtualization type
11
It loops through some possible configurations and return a string with
12
the name of the technology being used or None if there's no match
14
def join_root_path(path):
15
return os.path.join(root_path, path)
17
xen_paths = ["proc/sys/xen", "proc/xen"]
18
xen_paths = map(join_root_path, xen_paths)
20
vz_path = os.path.join(root_path, "proc/vz")
21
if os.path.exists(vz_path):
24
elif filter(os.path.exists, xen_paths):
27
# /sys/bus/xen exists on most machines, but only virtual machines have
29
sys_xen_path = join_root_path("sys/bus/xen/devices")
30
if os.path.isdir(sys_xen_path) and os.listdir(sys_xen_path):
33
cpu_info_path = os.path.join(root_path, "proc/cpuinfo")
34
if os.path.exists(cpu_info_path):
36
fd = open(cpu_info_path)
38
if "QEMU Virtual CPU" in cpuinfo:
43
sys_vendor_path = os.path.join(root_path, "sys", "class", "dmi", "id",
45
if os.path.exists(sys_vendor_path):
47
fd = open(sys_vendor_path)
48
file_content = fd.read()
49
if "VMware, Inc." in file_content: