Class: Fog::CurrentMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-fog/core/current_machine.rb

Constant Summary collapse

AMAZON_AWS_CHECK_IP =
'http://checkip.amazonaws.com'
@@lock =
Mutex.new

Class Method Summary collapse

Class Method Details

.ip_addressObject

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.

Examples:

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

Raises:

  • (Net::HTTPExceptions)

    if the net/http request fails.



28
29
30
31
32
# File 'lib/rackspace-fog/core/current_machine.rb', line 28

def self.ip_address
  @@lock.synchronize do
    @@ip_address ||= Excon.get(AMAZON_AWS_CHECK_IP).body.chomp
  end
end

.ip_address=(ip_address) ⇒ Object



7
8
9
10
11
# File 'lib/rackspace-fog/core/current_machine.rb', line 7

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