Module: Chef::Sugar::IP

Extended by:
IP
Included in:
IP
Defined in:
lib/chef/sugar/ip.rb

Instance Method Summary collapse

Instance Method Details

#best_ip_for(node, other) ⇒ Object

The best IP address for the given node, in the context of the current node. Useful for choosing a local IP address over a public one to limit bandwidth on cloud providers.

Parameters:

  • other (Chef::Node)

    the node to calculate the best IP address for


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/sugar/ip.rb', line 30

def best_ip_for(node, other)
  if other['cloud']
    if node['cloud'] && other['cloud']['provider'] == node['cloud']['provider']
      other['cloud']['local_ipv4']
    else
      other['cloud']['public_ipv4']
    end
  else
    other['ipaddress']
  end
end