Sha256: 23b177301219e0374f8648a7dbcd3f44f4bf4ddb54abad7479745ef47a3ebe18
Contents?: true
Size: 994 Bytes
Versions: 3
Compression:
Stored size: 994 Bytes
Contents
require "thread" module Fog class CurrentMachine @lock = Mutex.new AMAZON_AWS_CHECK_IP = "http://checkip.amazonaws.com".freeze 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fog-core-2.6.0 | lib/fog/core/current_machine.rb |
fog-core-2.5.0 | lib/fog/core/current_machine.rb |
fog-core-2.4.0 | lib/fog/core/current_machine.rb |