Class: Emissary::Identity::Unix

Inherits:
Emissary::Identity show all
Defined in:
lib/emissary/identity/unix.rb

Constant Summary

Constants inherited from Emissary::Identity

EXTERNAL_IDENTITY_GLOB, INTERNAL_IDENTITY_GLOB

Instance Attribute Summary

Attributes inherited from Emissary::Identity

#loaded, #methods

Instance Method Summary collapse

Methods inherited from Emissary::Identity

exclude, exclusions, #identifiers, #initialize, instance, #method_missing, new, register, #to_h, #to_s

Constructor Details

This class inherits a constructor from Emissary::Identity

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Emissary::Identity

Instance Method Details

#account_idObject



43
44
45
# File 'lib/emissary/identity/unix.rb', line 43

def 
  ENV['ACCOUNT_ID'] || -1
end

#cluster_idObject



39
40
41
# File 'lib/emissary/identity/unix.rb', line 39

def cluster_id
  ENV['CLUSTER_ID'] || -1
end

#instance_idObject



31
32
33
# File 'lib/emissary/identity/unix.rb', line 31

def instance_id
  ENV['INSTANCE_ID'] || -1
end

#local_ipObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/emissary/identity/unix.rb', line 47

def local_ip
  @ip_local ||= begin
    # turn off reverse DNS resolution temporarily
    orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  
    @ip_local = UDPSocket.open { |s| s.connect IP_CHECK_DOMAIN, 1; s.addr.last }
  rescue
    nil
  ensure
    Socket.do_not_reverse_lookup = orig rescue nil
  end
end

#nameObject Also known as: queue_name



21
22
23
# File 'lib/emissary/identity/unix.rb', line 21

def name
  @hostname ||= `uname -n`.strip
end

#public_ipObject



59
60
61
62
63
64
65
# File 'lib/emissary/identity/unix.rb', line 59

def public_ip
  @ip_public ||= begin
    Net::HTTP.get(URI.parse(IP_CHECK_URL)).gsub(/.*?((\d{1,3}\.){3}\d{1,3}).*/m, '\1')
  rescue
    nil
  end
end

#rolesObject



27
28
29
# File 'lib/emissary/identity/unix.rb', line 27

def roles
  ENV['ROLES'] || ''
end

#server_idObject



35
36
37
# File 'lib/emissary/identity/unix.rb', line 35

def server_id
  ENV['SERVER_ID'] || -1
end