diff options
author | root <root@puppetmaster.black.co.at> | 2007-10-01 21:03:27 +0200 |
---|---|---|
committer | root <root@puppetmaster.black.co.at> | 2007-10-01 21:03:27 +0200 |
commit | dbf92194b77f5545ab67a9ea83241102406b4392 (patch) | |
tree | 2009d4dff710cf31d9d2f65e0b3c55c0c4c99665 | |
parent | 32b0c131acca2640ace7ff6c714409b25d4b7742 (diff) | |
download | puppet-common-dbf92194b77f5545ab67a9ea83241102406b4392.tar.gz puppet-common-dbf92194b77f5545ab67a9ea83241102406b4392.tar.bz2 |
common: add netmask fact for automatic syncing
-rw-r--r-- | plugins/facter/netmask.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/plugins/facter/netmask.rb b/plugins/facter/netmask.rb new file mode 100644 index 0000000..3edf2b6 --- /dev/null +++ b/plugins/facter/netmask.rb @@ -0,0 +1,47 @@ +# netmask.rb -- find the netmask of the primary ipaddress +# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at> +# Copyright (C) 2007 Mark 'phips' Phillips +# See LICENSE for the full license granted to you. +# idea and originial source by Mark 'phips' Phillips + +def get_netmask + netmask = nil; + ipregex = %r{(\d{1,3}\.){3}\d{1,3}} + + ops = nil + case Facter.kernel + when 'Linux' + ops = { + :ifconfig => '/sbin/ifconfig', + :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x, + :munge => nil, + } + when 'SunOS' + ops = { + :ifconfig => '/usr/sbin/ifconfig -a', + :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x, + :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } + } + end + + %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line| + matches = line.match(ops[:regex]) + if !matches.nil? + if ops[:munge].nil? + netmask = matches[1] + else + netmask = ops[:munge].call(matches[1]) + end + end + end + netmask +end + +Facter.add("netmask") do + confine :kernel => [ :sunos, :linux ] + setcode do + get_netmask + end +end + + |