Sha256: d72f0cca9aee2924eaf79ffbde51c67ae84e62d609ee74fdab0e3e2b5c45e8db

Contents?: true

Size: 1.48 KB

Versions: 44

Compression:

Stored size: 1.48 KB

Contents

module Specinfra
  class HostInventory
    class Virtualization < Base
      def get
        res = {}
        ## docker
        if backend.run_command('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.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 and ret.stdout.length > 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', 'qemu'
          detected
        when 'oracle'
          'vbox'
        end
      end

    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
specinfra-2.79.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.78.2 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.78.1 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.78.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.77.3 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.77.2 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.77.1 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.77.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.9 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.8 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.7 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.6 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.5 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.4 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.3 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.2 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.1 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.76.0 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.75.1 lib/specinfra/host_inventory/virtualization.rb
specinfra-2.75.0 lib/specinfra/host_inventory/virtualization.rb