Sha256: 4021ea0163a118c4497943140251fb42d809757671041204639fd8e6f3d21402

Contents?: true

Size: 1.4 KB

Versions: 40

Compression:

Stored size: 1.4 KB

Contents

module Specinfra
  class HostInventory
    class Virtualization < Base
      def get
        res = {}
        ## docker 
        if backend.run_command('ls /.dockerinit').success?
          res[:system] = 'docker'
          return res
        end

        ## OpenVZ on Linux 
        if backend.run_command('test -d /proc/vz -a ! -d /proc/bc').success?
          res[:system] = 'openvz'
          return res
        end

        cmd = backend.command.get(:get_inventory_system_product_name)
        ret = backend.run_command(cmd)
        if ret.exit_status == 0
           res[:system] = parse_system_product_name(ret.stdout)   
           return res
        end

        ret = backend.run_command('systemd-detect-virt')
        if ret.success?
          res[:system] = parse_systemd_detect_virt_output(ret.stdout)
        end

        res 
      end 

      def parse_system_product_name(ret)
        product_name = case ret
          when /.*VMware Virtual Platform/
            'vmware'
          when /.*VirtualBox/
            'vbox'
          when /.*KVM/
            'kvm'
          when /.*OpenStack/
            'openstack'
          else
            nil
        end
        product_name
      end

      def parse_systemd_detect_virt_output(ret)
        detected = ret.strip

        case detected
        when 'vmware', 'kvm'
          detected
        when 'oracle'
          'vbox'
        end
      end

    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
specinfra-2.67.7 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.67.6 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.67.5 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.67.3 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.67.2 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.67.1 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.67.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.9 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.8 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.7 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.6 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.5 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.4 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.3 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.2 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.1 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.66.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.65.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.64.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.63.3 lib/specinfra/host_inventory/virtualization.rb