Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python2.7 / dist-packages / landscape / lib / | server ip : 172.67.156.115 your ip : 172.70.179.190 H O M E |
Filename | /usr/lib/python2.7/dist-packages/landscape/lib/vm_info.py |
Size | 1.95 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 20-Feb-2014 23:01 |
Last accessed | 07-Jul-2025 02:08 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
"""
Network introspection utilities using ioctl and the /proc filesystem.
"""
import os
from landscape.lib.fs import read_file
def get_vm_info(root_path="/"):
"""
Return a string with the virtualization type if it's known, an empty string
otherwise.
It loops through some possible configurations and return a string with
the name of the technology being used or None if there's no match
"""
def join_root_path(path):
return os.path.join(root_path, path)
xen_paths = ["proc/sys/xen", "proc/xen"]
xen_paths = map(join_root_path, xen_paths)
vz_path = join_root_path("proc/vz")
if os.path.exists(vz_path):
return "openvz"
elif filter(os.path.exists, xen_paths):
return "xen"
# /sys/bus/xen exists on most machines, but only virtual machines have
# devices
sys_xen_path = join_root_path("sys/bus/xen/devices")
if os.path.isdir(sys_xen_path) and os.listdir(sys_xen_path):
return "xen"
sys_vendor_path = join_root_path("sys/class/dmi/id/sys_vendor")
if not os.path.exists(sys_vendor_path):
# Some virtualised CPU architectures indicate this via cpuinfo
cpuinfo_path = join_root_path("proc/cpuinfo")
if os.path.exists(cpuinfo_path):
cpuinfo = read_file(cpuinfo_path)
if "qemu" in cpuinfo:
return "kvm"
return ""
vendor = read_file(sys_vendor_path)
content_vendors_map = (
("VMware, Inc.", "vmware"),
("Microsoft Corporation", "hyperv"),
("Bochs", "kvm"),
("OpenStack", "kvm"),
("innotek GmbH", "virtualbox"))
for name, vm_type in content_vendors_map:
if name in vendor:
return vm_type
return ""
def get_container_info(path="/run/container_type"):
"""
Return a string with the type of container the client is running in, if
any, an empty string otherwise.
"""
return read_file(path).strip() if os.path.exists(path) else ""
Network introspection utilities using ioctl and the /proc filesystem.
"""
import os
from landscape.lib.fs import read_file
def get_vm_info(root_path="/"):
"""
Return a string with the virtualization type if it's known, an empty string
otherwise.
It loops through some possible configurations and return a string with
the name of the technology being used or None if there's no match
"""
def join_root_path(path):
return os.path.join(root_path, path)
xen_paths = ["proc/sys/xen", "proc/xen"]
xen_paths = map(join_root_path, xen_paths)
vz_path = join_root_path("proc/vz")
if os.path.exists(vz_path):
return "openvz"
elif filter(os.path.exists, xen_paths):
return "xen"
# /sys/bus/xen exists on most machines, but only virtual machines have
# devices
sys_xen_path = join_root_path("sys/bus/xen/devices")
if os.path.isdir(sys_xen_path) and os.listdir(sys_xen_path):
return "xen"
sys_vendor_path = join_root_path("sys/class/dmi/id/sys_vendor")
if not os.path.exists(sys_vendor_path):
# Some virtualised CPU architectures indicate this via cpuinfo
cpuinfo_path = join_root_path("proc/cpuinfo")
if os.path.exists(cpuinfo_path):
cpuinfo = read_file(cpuinfo_path)
if "qemu" in cpuinfo:
return "kvm"
return ""
vendor = read_file(sys_vendor_path)
content_vendors_map = (
("VMware, Inc.", "vmware"),
("Microsoft Corporation", "hyperv"),
("Bochs", "kvm"),
("OpenStack", "kvm"),
("innotek GmbH", "virtualbox"))
for name, vm_type in content_vendors_map:
if name in vendor:
return vm_type
return ""
def get_container_info(path="/run/container_type"):
"""
Return a string with the type of container the client is running in, if
any, an empty string otherwise.
"""
return read_file(path).strip() if os.path.exists(path) else ""