Sha256: 0c527cd15c63f0b00324addbc435e4795de6e5203cf12a80524e1f0013a3e3d8

Contents?: true

Size: 987 Bytes

Versions: 46

Compression:

Stored size: 987 Bytes

Contents

require "thread"

module Fog
  class CurrentMachine
    @lock = Mutex.new

    AMAZON_AWS_CHECK_IP = "http://checkip.amazonaws.com"

    def self.ip_address=(ip_address)
      @lock.synchronize do
        @ip_address = ip_address
      end
    end

    # Get the ip address of the machine from which this command is run. It is
    # recommended that you surround calls to this function with a timeout block
    # to ensure optimum performance in the case where the amazonaws checkip
    # service is unavailable.
    #
    # @example Get the current ip address
    #   begin
    #     Timeout::timeout(5) do
    #       puts "Your ip address is #{Fog::CurrentMachine.ip_address}"
    #     end
    #   rescue Timeout::Error
    #     puts "Service timeout"
    #   end
    #
    # @raise [Excon::Errors::Error] if the net/http request fails.
    def self.ip_address
      @lock.synchronize do
        @ip_address ||= Excon.get(AMAZON_AWS_CHECK_IP).body.chomp
      end
    end
  end
end

Version data entries

46 entries across 43 versions & 3 rubygems

Version Path
fog-core-2.3.0 lib/fog/core/current_machine.rb
fog-core-2.2.4 lib/fog/core/current_machine.rb
fog-core-2.2.3 lib/fog/core/current_machine.rb
fog-core-2.2.2 lib/fog/core/current_machine.rb
fog-core-2.2.1 lib/fog/core/current_machine.rb
fog-core-2.2.0 lib/fog/core/current_machine.rb
fog-core-2.1.2 lib/fog/core/current_machine.rb
fog-core-2.1.1 lib/fog/core/current_machine.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-core-1.45.0/lib/fog/core/current_machine.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-core-1.45.0/lib/fog/core/current_machine.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-core-2.1.0/lib/fog/core/current_machine.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-core-1.45.0/lib/fog/core/current_machine.rb
fog-core-2.1.0 lib/fog/core/current_machine.rb
fog-core-2.0.0 lib/fog/core/current_machine.rb
fog-core-1.45.0 lib/fog/core/current_machine.rb
fog-core-1.44.3 lib/fog/core/current_machine.rb
fog-core-1.44.2 lib/fog/core/current_machine.rb
fog-core-1.44.1 lib/fog/core/current_machine.rb
fog-core-1.44.0 lib/fog/core/current_machine.rb
fog-core-1.43.0 lib/fog/core/current_machine.rb