Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtualization does not detect centos 7.1 kvm guests running on a centos 7.1 host #590

Closed
conathan opened this issue Jul 30, 2015 · 4 comments
Labels
Status: Good First Issue An issue ready for a new contributor.

Comments

@conathan
Copy link

Looking at https://github.com/chef/ohai/blob/master/lib/ohai/plugins/linux/virtualization.rb, It uses the following to detect whenever it is running as a kvm guest:

  if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
    virtualization[:system] = "kvm"
    virtualization[:role] = "guest"
    virtualization[:systems][:kvm] = "guest"

  when /Manufacturer: QEMU/
    virtualization[:system] = "kvm"
    virtualization[:role] = "guest"
    virtualization[:systems][:kvm] = "guest"

In this case, I have the following for cpuinfo:
vendor_id : GenuineIntel
model name : Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz

and for dmidecode

Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: Red Hat
Product Name: KVM
Version: RHEL 7.0.0 PC (i440FX + PIIX, 1996)
Serial Number: Not Specified
UUID: 6E56CFE2-2088-4A46-906A-FC49EDC4072C
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Red Hat Enterprise Linux

I worked around that by using the following:

  require 'ohai/util/file_helper'

  include Ohai::Util::FileHelper

  Ohai.plugin(:VirtualizationKvm) do
    provides "virtualization"
    collect_data(:linux) do
      # http://www.dmo.ca/blog/detecting-virtualization-on-linux
      if File.exists?("/usr/sbin/dmidecode")
        so = shell_out("dmidecode")
        case so.stdout
        when /Product Name: KVM/
          virtualization[:system] = "kvm"
          virtualization[:role] = "guest"
          virtualization[:systems][:kvm] = "guest"
        else
          nil
        end
      end
    end
  end
@mcquin
Copy link
Contributor

mcquin commented Aug 6, 2015

Thanks for the infos.

It looks like we'll just have to change this line to

when /Manufacturer: QEMU|Product Name: KVM/

@mcquin
Copy link
Contributor

mcquin commented Aug 6, 2015

#594

@conathan
Copy link
Author

conathan commented Aug 6, 2015

Thank you, new virtualization.rb seems to work (used ohai-8.5.0 and just grabbed the latest plugins/linux/virtualization.rb from the above pull).

@mcquin
Copy link
Contributor

mcquin commented Aug 6, 2015

Great! Thanks for the check @conathan ! :)

mcquin added a commit that referenced this issue Aug 7, 2015
Detect KVM guest from dmidecode
@chef chef locked and limited conversation to collaborators Nov 16, 2017
@tas50 tas50 added Status: Good First Issue An issue ready for a new contributor. and removed Help: Good First Issue labels Jan 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: Good First Issue An issue ready for a new contributor.
Projects
None yet
Development

No branches or pull requests

4 participants