lib/facter/util/ip.rb in facter-1.6.12 vs lib/facter/util/ip.rb in facter-1.6.13.rc1
- old
+ new
@@ -5,11 +5,11 @@
# a given platform or set of platforms.
REGEX_MAP = {
:linux => {
:ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
:ipaddress6 => /inet6 addr: ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/,
- :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
+ :macaddress => /(?:ether|HWaddr)\s+((\w{1,2}:){5,}\w{1,2})/,
:netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
},
:bsd => {
:aliases => [:openbsd, :netbsd, :freebsd, :darwin, :"gnu/kfreebsd", :dragonfly],
:ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
@@ -72,11 +72,11 @@
end
def self.get_all_interface_output
case Facter.value(:kernel)
when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
- output = %x{/sbin/ifconfig -a}
+ output = %x{/sbin/ifconfig -a 2>/dev/null}
when 'SunOS'
output = %x{/usr/sbin/ifconfig -a}
when 'HP-UX'
output = %x{/bin/netstat -in | sed -e 1d}
when 'windows'
@@ -84,14 +84,39 @@
output += %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show interface|
end
output
end
+ def self.get_infiniband_macaddress(interface)
+ if File::exist?("/sys/class/net/#{interface}/address") then
+ ib_mac_address = `cat /sys/class/net/#{interface}/address`.chomp
+ elsif File::exist?("/sbin/ip") then
+ ip_output = %x{/sbin/ip link show #{interface}}
+ ib_mac_address = ip_output.scan(%r{infiniband\s+((\w{1,2}:){5,}\w{1,2})})
+ else
+ ib_mac_address = "FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF"
+ Facter.debug("ip.rb: nothing under /sys/class/net/#{interface}/address and /sbin/ip not available")
+ end
+ ib_mac_address
+ end
+
+ def self.ifconfig_interface(interface)
+ %x{/sbin/ifconfig #{interface} 2>/dev/null}
+ end
+
def self.get_single_interface_output(interface)
output = ""
case Facter.value(:kernel)
- when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
- output = %x{/sbin/ifconfig #{interface}}
+ when 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
+ output = Facter::Util::IP.ifconfig_interface(interface)
+ when 'Linux'
+ ifconfig_output = Facter::Util::IP.ifconfig_interface(interface)
+ if interface =~ /^ib/ then
+ real_mac_address = get_infiniband_macaddress(interface)
+ output = ifconfig_output.sub(%r{(?:ether|HWaddr)\s+((\w{1,2}:){5,}\w{1,2})}, "HWaddr #{real_mac_address}")
+ else
+ output = ifconfig_output
+ end
when 'SunOS'
output = %x{/usr/sbin/ifconfig #{interface}}
when 'HP-UX'
mac = ""
ifc = %x{/usr/sbin/ifconfig #{interface}}