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