summaryrefslogtreecommitdiffstats
path: root/lib/facter/ipmess.rb
blob: 2887b64d04767a20b344534c7aca3f5f337598aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# ipmess.rb
# Try to get additional Facts about the machine's network interfaces
#
# Original concept Copyright (C) 2007 psychedelys <psychedelys@gmail.com>
# Update and *BSD support (C) 2007 James Turnbull <james@lovedthanlost.net>
#

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 => Facter::Util::IP.supported_platforms
    setcode do
        Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",")
    end
end

Facter::Util::IP.get_interfaces.each do |interface|
    mi = Facter::Util::IP.alphafy(interface)

    # 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
                Facter::Util::IP.get_interface_value(interface, label)
            end
        end
    end
end