Codebase list facter / acf0bb2
Ensures that ARP facts are returned only on EC2 hosts ARP facts on large network might lead to inconstant values as we are always using the first ARP entry from the output of the ARP command Signed-off-by: Ohad Levy <ohadlevy@gmail.com> Ohad Levy authored 13 years ago Jacob Helwig committed 13 years ago
2 changed file(s) with 13 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
22 Facter.add(:arp) do
33 confine :kernel => :linux
44 setcode do
5 arp = []
65 output = Facter::Util::Resolution.exec('arp -a')
76 if not output.nil?
7 arp = ""
88 output.each_line do |s|
9 arp.push($1) if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/
9 if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/
10 arp = $1
11 break # stops on the first match
12 end
1013 end
1114 end
12 arp[0]
15 EC2_ARP == arp ? arp : nil
1316 end
1417 end
1518
1720 Facter.add("arp_" + Facter::Util::IP.alphafy(interface)) do
1821 confine :kernel => :linux
1922 setcode do
20 Facter::Util::IP.get_arp_value(interface)
23 arp = Facter::Util::IP.get_arp_value(interface)
24 EC2_ARP == arp ? arp : nil
2125 end
2226 end
2327 end
55 require 'open-uri'
66 require 'socket'
77
8 EC2_ADDR = "169.254.169.254"
8 EC2_ADDR = "169.254.169.254"
99 EC2_METADATA_URL = "http://#{EC2_ADDR}/2008-02-01/meta-data"
1010 EC2_USERDATA_URL = "http://#{EC2_ADDR}/2008-02-01/user-data"
11 EC2_ARP = "fe:ff:ff:ff:ff:ff"
12 EC2_EUCA_MAC = %r{^[dD]0:0[dD]:}
1113
1214 def can_metadata_connect?(addr, port, timeout=2)
1315 t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
6062 end
6163
6264 def has_euca_mac?
63 if Facter.value(:macaddress) =~ /^[dD]0:0[dD]:/
64 return true
65 else
66 return false
67 end
65 !!(Facter.value(:macaddress) =~ EC2_EUCA_MAC)
6866 end
6967
7068 def has_ec2_arp?
71 if Facter.value(:arp) == 'fe:ff:ff:ff:ff:ff'
72 return true
73 else
74 return false
75 end
69 !!(Facter.value(:arp) == EC2_ARP)
7670 end
7771
7872 if (has_euca_mac? || has_ec2_arp?) && can_metadata_connect?(EC2_ADDR,80)