Sha256: 244e087e81059e0a67d817a5b684870f3f7b6cfce7d93985bb85b8d2b9980a45

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class Cloud < BaseResolver
      # cloud_provider

      init_resolver

      class << self
        private

        def post_resolve(fact_name)
          @fact_list.fetch(fact_name) { detect_azure(fact_name) }
        end

        def detect_azure(fact_name)
          search_dirs = %w[/var/lib/dhcp /var/lib/NetworkManager]
          search_dirs.each do |path|
            next if !File.readable?(path) || !File.directory?(path)

            files = Dir.entries(path)
            files.select! { |filename| filename =~ /^dhclient.*lease.*$/ }
            files.each do |file|
              path = File.join([path, file])
              output = Facter::Util::FileHelper.safe_read(path)

              if output.include?('option unknown-245') || output.include?('option 245')
                @fact_list[:cloud_provider] = 'azure'
                return @fact_list[fact_name]
              end
            end
          end
          nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facter-4.0.49 lib/facter/resolvers/cloud.rb
facter-4.0.48 lib/facter/resolvers/cloud.rb
facter-4.0.47 lib/facter/resolvers/cloud.rb