~ubuntu-branches/ubuntu/trusty/facter/trusty

« back to all changes in this revision

Viewing changes to lib/facter/util/netmask.rb

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock, Nigel Kersten, Andrew Pollock
  • Date: 2009-04-13 15:20:21 UTC
  • mfrom: (1.1.5 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090413152021-t3uagjamr3ee4njl
Tags: 1.5.4-1
[ Nigel Kersten ]
* New upstream release
* Switch maintainer to pkg-puppet-devel list
* Modify uploaders
* Update watch file regexp to exclude release canditate tarballs
* Use upstream install.rb script to build rather than copying manually

[ Andrew Pollock ]
* debian/control: add libopenssl-ruby to build dependencies
* debian/control: bump Standards-Version (no changes)
* debian/compat: increase to 5
* debian/control: add pciutils and ${misc:Depends} to dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
module Facter::NetMask
2
 
 
3
 
def self.get_netmask
 
2
    def self.get_netmask
4
3
        netmask = nil;
5
4
        ipregex = %r{(\d{1,3}\.){3}\d{1,3}}
6
5
 
7
6
        ops = nil
8
7
        case Facter.value(:kernel)
9
 
                when 'Linux'
10
 
                        ops = {
11
 
                                :ifconfig => '/sbin/ifconfig',
12
 
                                :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
13
 
                                :munge => nil,
14
 
                        }
15
 
                when 'SunOS'
16
 
                        ops = {
17
 
                                :ifconfig => '/usr/sbin/ifconfig -a',
18
 
                                :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x,
19
 
                                :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
20
 
                        }
 
8
        when 'Linux'
 
9
            ops = {
 
10
                :ifconfig => '/sbin/ifconfig',
 
11
                :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
 
12
                :munge => nil,
 
13
            }
 
14
        when 'SunOS'
 
15
            ops = {
 
16
                :ifconfig => '/usr/sbin/ifconfig -a',
 
17
                :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x,
 
18
                :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
 
19
            }
21
20
        end
22
21
 
23
22
        %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line|
24
 
                matches = line.match(ops[:regex])
25
 
                if !matches.nil?
26
 
                        if ops[:munge].nil?
27
 
                                netmask = matches[1]
28
 
                        else
29
 
                                netmask = ops[:munge].call(matches[1])
30
 
                        end
 
23
            matches = line.match(ops[:regex])
 
24
            if !matches.nil?
 
25
                if ops[:munge].nil?
 
26
                    netmask = matches[1]
 
27
                else
 
28
                    netmask = ops[:munge].call(matches[1])
31
29
                end
 
30
            end
32
31
        end
33
32
        netmask
34
 
end
35
 
 
 
33
    end
36
34
end