Sha256: a984c50c8f54df301ce9bd5acea02b1dd3def4af0574203208a42685b215b522

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 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 = 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

1 entries across 1 versions & 1 rubygems

Version Path
facter-4.0.46 lib/facter/resolvers/cloud.rb