Provide a set of utility static methods that help with resolving the EC2 fact.
Test if we can connect to the EC2 api. Return true if able to connect. On failure this function fails silently and returns false.
The wait_sec parameter provides you with an adjustable timeout.
# File lib/facter/util/ec2.rb, line 13 def can_connect?(wait_sec=2) url = "http://169.254.169.254:80/" Timeout::timeout(wait_sec) {open(url)} return true rescue Timeout::Error return false rescue return false end
Test if the host has an arp entry in its cache that matches the EC2 arp, which is normally +fe:ff:ff:ff:ff:ff+.
# File lib/facter/util/ec2.rb, line 37 def has_ec2_arp? mac_address = "fe:ff:ff:ff:ff:ff" if Facter.value(:kernel) == 'windows' arp_command = "arp -a" mac_address.gsub!(":","-") else arp_command = "arp -an" end arp_table = Facter::Util::Resolution.exec(arp_command) if not arp_table.nil? arp_table.each_line do |line| return true if line.downcase.include?(mac_address) end end return false end
Generated with the Darkfish Rdoc Generator 2.