~fcorrea/landscape-client/add-vminfo-to-computer-info-message

« back to all changes in this revision

Viewing changes to landscape/monitor/computerinfo.py

  • Committer: Fernando Correa Neto
  • Date: 2011-04-20 21:16:00 UTC
  • Revision ID: fernando.neto@canonical.com-20110420211600-tcqm6jun27zbxeoy
- Addressing final therve and free review comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        the name of the technology being used or None if there's no match
105
105
        """
106
106
        virt_info = ""
107
 
        exists = os.path.exists
108
 
        path_join = os.path.join
109
107
 
110
108
        def join_root_path(path):
111
 
            return path_join(self._root_path, path)
 
109
            return os.path.join(self._root_path, path)
112
110
 
113
111
        xen_paths = ["proc/sys/xen", "sys/bus/xen", "proc/xen"]
114
112
        xen_paths = map(join_root_path, xen_paths)
115
113
 
116
 
        vz_path = join_root_path("proc/vz")
117
 
        if exists(vz_path):
 
114
        vz_path = os.path.join(self._root_path, "proc/vz")
 
115
        if os.path.exists(vz_path):
118
116
            virt_info = "openvz"
119
117
 
120
 
        elif filter(exists, xen_paths):
 
118
        elif filter(os.path.exists, xen_paths):
121
119
            virt_info = "xen"
122
120
 
123
 
        elif exists(join_root_path("proc/cpuinfo")):
124
 
            with open(join_root_path("proc/cpuinfo")) as cpuinfo:
125
 
                if "QEMU Virtual CPU" in cpuinfo.read():
 
121
        cpu_info_path = os.path.join(self._root_path, "proc/cpuinfo")
 
122
        if os.path.exists(cpu_info_path):
 
123
            try:
 
124
                fd = open(cpu_info_path)
 
125
                cpuinfo = fd.read()
 
126
                if "QEMU Virtual CPU" in cpuinfo:
126
127
                    virt_info = "kvm"
 
128
            finally:
 
129
                fd.close()
127
130
 
128
131
        return virt_info