ferm: open ssh from mirror-master to ports mirror
[mirror/dsa-puppet.git] / modules / debian_org / lib / facter / ipaddresses.rb
1 Facter.add("v4ips") do
2         confine :kernel => :linux
3         addrs = []
4         if FileTest.exist?("/bin/ip")
5                 %x{ip addr list}.each_line do |line|
6                         next unless line =~ /\s+inet/
7                         next if line =~ /scope (link|host)/
8                         if line =~ /\s+inet\s+(\S+)\/\d{1,2} .*/
9                                 addrs << $1
10                         end
11                 end
12         end
13         ret = addrs.join(",")
14         if ret.empty?
15                 ret = ''
16         end
17         setcode do
18                 ret
19         end
20 end
21
22 Facter.add("v4ips") do
23         confine :kernel => 'GNU/kFreeBSD'
24         setcode do
25                 addrs = []
26                 output = %x{/sbin/ifconfig}
27
28                 output.split(/^\S/).each { |str|
29                         if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
30                                 tmp = $1
31                                 unless tmp =~ /127\./
32                                         addrs << tmp
33                                         break
34                                 end
35                         end
36                 }
37
38                 ret = addrs.join(",")
39                 if ret.empty?
40                         ret = ''
41                 end
42                 ret
43         end
44 end
45
46 Facter.add("v6ips") do
47         confine :kernel => :linux
48         addrs = []
49         if FileTest.exist?("/bin/ip")
50                 %x{ip addr list}.each_line do |line|
51                         next unless line =~ /\s+inet/
52                         next if line =~ /scope (link|host)/
53                         if line =~ /\s+inet6\s+(\S+)\/\d{1,3} .*/
54                                 addrs << $1
55                         end
56                 end
57         end
58         ret = addrs.join(",")
59         if ret.empty?
60                 ret = ''
61         end
62         setcode do
63                 ret
64         end
65 end
66