~ubuntu-branches/ubuntu/lucid/landscape-client/lucid-updates

« back to all changes in this revision

Viewing changes to landscape/lib/vm_info.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2012-04-10 14:28:48 UTC
  • mfrom: (1.1.27)
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: package-import@ubuntu.com-20120410142848-7xsy4g2xii7y7ntc
ImportĀ upstreamĀ versionĀ 12.04.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Network introspection utilities using ioctl and the /proc filesystem.
 
3
"""
 
4
import os
 
5
 
 
6
 
 
7
def get_vm_info(root_path="/"):
 
8
    """
 
9
    This is a utility that returns the virtualization type
 
10
 
 
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
 
13
    """
 
14
    def join_root_path(path):
 
15
        return os.path.join(root_path, path)
 
16
 
 
17
    xen_paths = ["proc/sys/xen", "proc/xen"]
 
18
    xen_paths = map(join_root_path, xen_paths)
 
19
 
 
20
    vz_path = os.path.join(root_path, "proc/vz")
 
21
    if os.path.exists(vz_path):
 
22
        return "openvz"
 
23
 
 
24
    elif filter(os.path.exists, xen_paths):
 
25
        return "xen"
 
26
 
 
27
    # /sys/bus/xen exists on most machines, but only virtual machines have
 
28
    # devices
 
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):
 
31
        return "xen"
 
32
 
 
33
    cpu_info_path = os.path.join(root_path, "proc/cpuinfo")
 
34
    if os.path.exists(cpu_info_path):
 
35
        try:
 
36
            fd = open(cpu_info_path)
 
37
            cpuinfo = fd.read()
 
38
            if "QEMU Virtual CPU" in cpuinfo:
 
39
                return "kvm"
 
40
        finally:
 
41
            fd.close()
 
42
 
 
43
    sys_vendor_path = os.path.join(root_path, "sys", "class", "dmi", "id",
 
44
                                   "sys_vendor")
 
45
    if os.path.exists(sys_vendor_path):
 
46
        try:
 
47
            fd = open(sys_vendor_path)
 
48
            file_content = fd.read()
 
49
            if "VMware, Inc." in file_content:
 
50
                return "vmware"
 
51
        finally:
 
52
            fd.close()
 
53
 
 
54
    return ""