diff options
author | Ohad Levy <ohadlevy@gmail.com> | 2011-03-22 23:04:23 +0200 |
---|---|---|
committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-04-06 16:13:26 -0700 |
commit | acf0bb21c88edb0eacf4ab73402614c721cf2f76 (patch) | |
tree | 7f7a92997478512842e5010af22a15d73d5842a3 /lib/facter/ec2.rb | |
parent | 76f544b261ec1c9712105773946fec7e6d76b4e9 (diff) | |
download | facter-acf0bb21c88edb0eacf4ab73402614c721cf2f76.tar.gz facter-acf0bb21c88edb0eacf4ab73402614c721cf2f76.tar.xz facter-acf0bb21c88edb0eacf4ab73402614c721cf2f76.zip |
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>
Diffstat (limited to 'lib/facter/ec2.rb')
-rw-r--r-- | lib/facter/ec2.rb | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb index 29b2a1c..693e78e 100644 --- a/lib/facter/ec2.rb +++ b/lib/facter/ec2.rb @@ -6,9 +6,11 @@ require 'open-uri' require 'socket' -EC2_ADDR = "169.254.169.254" +EC2_ADDR = "169.254.169.254" EC2_METADATA_URL = "http://#{EC2_ADDR}/2008-02-01/meta-data" EC2_USERDATA_URL = "http://#{EC2_ADDR}/2008-02-01/user-data" +EC2_ARP = "fe:ff:ff:ff:ff:ff" +EC2_EUCA_MAC = %r{^[dD]0:0[dD]:} def can_metadata_connect?(addr, port, timeout=2) t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) @@ -61,19 +63,11 @@ def userdata() end def has_euca_mac? - if Facter.value(:macaddress) =~ /^[dD]0:0[dD]:/ - return true - else - return false - end + !!(Facter.value(:macaddress) =~ EC2_EUCA_MAC) end def has_ec2_arp? - if Facter.value(:arp) == 'fe:ff:ff:ff:ff:ff' - return true - else - return false - end + !!(Facter.value(:arp) == EC2_ARP) end if (has_euca_mac? || has_ec2_arp?) && can_metadata_connect?(EC2_ADDR,80) |