Class: Specinfra::HostInventory::Virtualization

Inherits:
Base
  • Object
show all
Defined in:
lib/specinfra/host_inventory/virtualization.rb

Instance Method Summary collapse

Methods inherited from Base

#backend, #initialize

Constructor Details

This class inherits a constructor from Specinfra::HostInventory::Base

Instance Method Details

#getObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/specinfra/host_inventory/virtualization.rb', line 4

def get
  res = {}
  if backend.run_command('ls /.dockerinit').success?
    res[:system] = 'docker'
    return res
  end

  if backend.run_command('ls /usr/sbin/dmidecode').success?
    ret = backend.run_command('dmidecode')
    if ret.exit_status == 0
      case ret.stdout
      when /Manufacturer: VMware/
        if ret.stdout =~ /Product Name: VMware Virtual Platform/
          res[:system] = 'vmware'
        end
      when /Manufacturer: Oracle Corporation/
        if ret.stdout =~ /Product Name: VirtualBox/
          res[:system] = 'vbox'
        end
      when /Product Name: KVM/
        res[:system] = 'kvm'
      when /Product Name: OpenStack/
        res[:system] = 'openstack'
      else
        nil
      end
    else
      nil
    end
  end

  res
end