diff options
author | Luke Kanies <luke@madstop.com> | 2009-01-04 17:29:59 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-01-15 12:55:28 -0600 |
commit | aa56886b1143d49173f4878a41107f55fece529c (patch) | |
tree | 43ce6e3cec4250de4c40457593da2e8897d7e325 /lib/facter/ipmess.rb | |
parent | 91e25b9cc12fcb5e8d684b6258aec20735b992e1 (diff) | |
download | facter-aa56886b1143d49173f4878a41107f55fece529c.tar.gz facter-aa56886b1143d49173f4878a41107f55fece529c.tar.xz facter-aa56886b1143d49173f4878a41107f55fece529c.zip |
Refactoring the IP support, and fixing #1846.
I've made the IPMess stuff a lot less messy, and refactored
a lot of the util/ip module, including naming it more sensibly.
The biggest changes are that I moved the big case statement into
a constant and then used a bit of dispatch-style logic to use it,
and I eliminated a bunch of duplicate code in the ipmess.rb file.
Added some test data for FreeBSD and fixed a bug in my map
logic pointed out by Paul Nasrat.
I've also fixed #1846, in that the interface list now s/:/_/g.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/facter/ipmess.rb')
-rw-r--r-- | lib/facter/ipmess.rb | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb index c61b1ec..2887b64 100644 --- a/lib/facter/ipmess.rb +++ b/lib/facter/ipmess.rb @@ -7,39 +7,26 @@ require 'facter/util/ip' +# Note that most of this only works on a fixed list of platforms; notably, Darwin +# is missing. + Facter.add(:interfaces) do - confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ] + confine :kernel => Facter::Util::IP.supported_platforms setcode do - Facter::IPAddress.get_interfaces.join(",") + Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",") end end -case Facter.value(:kernel) -when 'SunOS', 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD' - Facter::IPAddress.get_interfaces.each do |interface| - mi = interface.gsub(/[:.]/, '_') - - Facter.add("ipaddress_" + mi) do - confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ] - setcode do - label = 'ipaddress' - Facter::IPAddress.get_interface_value(interface, label) - end - end - - Facter.add("macaddress_" + mi) do - confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ] - setcode do - label = 'macaddress' - Facter::IPAddress.get_interface_value(interface, label) - end - end +Facter::Util::IP.get_interfaces.each do |interface| + mi = Facter::Util::IP.alphafy(interface) - Facter.add("netmask_" + mi) do - confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ] + # Make a fact for each detail of each interface. Yay. + # There's no point in confining these facts, since we wouldn't be able to create + # them if we weren't running on a supported platform. + %w{ipaddress macaddress netmask}.each do |label| + Facter.add(label + "_" + mi) do setcode do - label = 'netmask' - Facter::IPAddress.get_interface_value(interface, label) + Facter::Util::IP.get_interface_value(interface, label) end end end |