Merge lp:~ack/landscape-client/detect-openstack-vm into lp:~landscape/landscape-client/trunk
Status: | Merged |
---|---|
Approved by: | Alberto Donato |
Approved revision: | 700 |
Merged at revision: | 695 |
Proposed branch: | lp:~ack/landscape-client/detect-openstack-vm |
Merge into: | lp:~landscape/landscape-client/trunk |
Diff against target: |
348 lines (+131/-114) 2 files modified
landscape/lib/tests/test_vm_info.py (+106/-91) landscape/lib/vm_info.py (+25/-23) |
To merge this branch: | bzr merge lp:~ack/landscape-client/detect-openstack-vm |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Geoff Teale (community) | Approve | ||
Björn Tillenius (community) | Approve | ||
Review via email: mp+171318@code.launchpad.net |
Commit message
This changes the detection logic for kvm virtual machines, looking for the "Bochs" as reported by OpenStack Folsom) or "OpenStack" (as reported by Grizzly) vendor in /sys rather than the CPU model.
It also refactors a bit the existing logic, and only tries to detect HyperV/VmWare/KVM if the "hypervisor" flag is present in /proc/cpuinfo, which is meant to report that the machine is running under an hypervisor.
Description of the change
This changes the detection logic for kvm virtual machines, looking for the "Bochs" as reported by OpenStack Folsom) or "OpenStack" (as reported by Grizzly) vendor in /sys rather than the CPU model.
It also refactors a bit the existing logic, and only tries to detect HyperV/VmWare/KVM if the "hypervisor" flag is present in /proc/cpuinfo, which is meant to report that the machine is running under an hypervisor.
Looks good! I have some nitpicks only.
[1]
Have you confirmed that this works on lucid and precise?
[2]
+ if line.startswith ("flags" ) and "hypervisor" in line:
+ has_hypervisor_flag = True
+ break
Can multiple lines start with flags? If not, it might be better to
write it as:
if line.startswith ("flags" ):
has_hypervisor _flag = "hypervisor" in line
break
[3]
+ if has_hypervisor_ flag: path("sys/ class/dmi/ id/sys_ vendor" ) exists( sys_vendor_ path): sys_vendor_ path)
+ sys_vendor_path = join_root_
+ if os.path.
+ content = read_file(
+ if "VMware, Inc." in content:
I tend to prefer early returns. I.e. at the top, return "" if there is
not hypervisor flag. That way you don't have to indent the main logic.