Sha256: 91d9b56dfddc6199c084989714da309f2de43f44c63a6c6dbc6613f56a9f7302

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Facts
  module Linux
    class Ec2Userdata
      FACT_NAME = 'ec2_userdata'

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

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

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

      private

      def aws_hypervisors?
        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

4 entries across 4 versions & 1 rubygems

Version Path
facter-4.0.39 lib/facter/facts/linux/ec2_userdata.rb
facter-4.0.38 lib/facter/facts/linux/ec2_userdata.rb
facter-4.0.37 lib/facter/facts/linux/ec2_userdata.rb
facter-4.0.36 lib/facter/facts/linux/ec2_userdata.rb