Sha256: 7becf79969e2a187829384d36c9d0c978bb4112d731a8ee858bbeb54b1c7729f

Contents?: true

Size: 989 Bytes

Versions: 86

Compression:

Stored size: 989 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

86 entries across 86 versions & 13 rubygems

Version Path
fog-core-1.24.0 lib/fog/core/current_machine.rb
fog-core-1.23.0 lib/fog/core/current_machine.rb
fog-core-1.22.0 lib/fog/core/current_machine.rb
fog-core-1.21.1 lib/fog/core/current_machine.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/core/current_machine.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/core/current_machine.rb
cifrado-0.2.1 vendor/fog/lib/fog/core/current_machine.rb
cifrado-0.2.0 vendor/fog/lib/fog/core/current_machine.rb
fog-core-1.21.0 lib/fog/core/current_machine.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/core/current_machine.rb
fog-1.20.0 lib/fog/core/current_machine.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/core/current_machine.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/core/current_machine.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/core/current_machine.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/core/current_machine.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/core/current_machine.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/core/current_machine.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/core/current_machine.rb
fog-1.19.0 lib/fog/core/current_machine.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/core/current_machine.rb