summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2011-03-08 20:18:30 +1100
committerJames Turnbull <james@lovedthanlost.net>2011-03-17 07:56:07 +1100
commit0411d2eacbfad9d07977dea8975b604b7cdd1aa5 (patch)
tree30c79a3b1a623a7bff5f8e68ec0c99d69d4bcc71 /lib
parent5b6f4fa4aae419bd2d65e1af6e185123dd432ac6 (diff)
downloadfacter-0411d2eacbfad9d07977dea8975b604b7cdd1aa5.tar.gz
facter-0411d2eacbfad9d07977dea8975b604b7cdd1aa5.tar.xz
facter-0411d2eacbfad9d07977dea8975b604b7cdd1aa5.zip
Fixed #2346 - Part 1: Added arp fact for Linux
Added facts arp (like the ipaddress etc) facts Added facts arp_interfacename
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/arp.rb22
-rw-r--r--lib/facter/util/ip.rb7
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/facter/arp.rb b/lib/facter/arp.rb
new file mode 100644
index 0000000..f4b7709
--- /dev/null
+++ b/lib/facter/arp.rb
@@ -0,0 +1,22 @@
+require 'facter/util/ip'
+
+Facter.add(:arp) do
+ confine :kernel => :linux
+ setcode do
+ arp = []
+ output = %x{/usr/sbin/arp -a}
+ output.each_line do |s|
+ arp.push($1) if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/
+ end
+ arp[0]
+ end
+end
+
+Facter::Util::IP.get_interfaces.each do |interface|
+ Facter.add("arp_" + Facter::Util::IP.alphafy(interface)) do
+ confine :kernel => :linux
+ setcode do
+ Facter::Util::IP.get_arp_value(interface)
+ end
+ end
+end
diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index e4370dc..8b6dbf4 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -169,4 +169,11 @@ module Facter::Util::IP
network = ip.mask(subnet.to_s).to_s
end
end
+
+ def self.get_arp_value(interface)
+ arp = Facter::Util::Resolution.exec("arp -en -i #{interface} | sed -e 1d")
+ if arp =~ /^\S+\s+\w+\s+(\S+)\s+\w\s+\S+$/
+ return $1
+ end
+ end
end