Sha256: 4d08db4569ece27bc6d9aacf7c6da1dfba24737dcd078f8560af62a69b4094c6

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Facts
  module Linux
    class Ec2Metadata
      FACT_NAME = 'ec2_metadata'

      def call_the_resolver
        return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws?

        fact_value = Facter::Resolvers::Ec2.resolve(:metadata)

        Facter::ResolvedFact.new(FACT_NAME, fact_value.empty? ? nil : fact_value)
      end

      def aws?
        virtual = check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci

        virtual == 'kvm' || virtual =~ /xen/
      end

      def check_virt_what
        Facter::Resolvers::VirtWhat.resolve(:vm)
      end

      def check_xen
        Facter::Resolvers::Xen.resolve(:vm)
      end

      def check_product_name
        product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
        return unless product_name

        Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
      end

      def check_bios_vendor
        bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
        return 'kvm' if bios_vendor&.include?('Amazon EC2')
      end

      def check_lspci
        Facter::Resolvers::Lspci.resolve(:vm)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.0.35 lib/facter/facts/linux/ec2_metadata.rb
facter-4.0.34 lib/facter/facts/linux/ec2_metadata.rb
facter-4.0.33 lib/facter/facts/linux/ec2_metadata.rb
facter-4.0.32 lib/facter/facts/linux/ec2_metadata.rb
facter-4.0.31 lib/facter/facts/linux/ec2_metadata.rb
facter-4.0.30 lib/facter/facts/linux/ec2_metadata.rb
facter-4.0.29 lib/facts/linux/ec2_metadata.rb
facter-4.0.28 lib/facts/linux/ec2_metadata.rb