~gandelman-a/ubuntu/precise/facter/merge922788

« back to all changes in this revision

Viewing changes to lib/facter/macaddress.rb

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2011-10-18 10:32:42 UTC
  • mfrom: (1.3.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: package-import@ubuntu.com-20111018103242-ag8i8vejfp8v7b1b
Tags: upstream-1.6.1
ImportĀ upstreamĀ versionĀ 1.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Fact: macaddress
 
2
#
 
3
# Purpose: 
 
4
#
 
5
# Resolution:
 
6
#
 
7
# Caveats:
 
8
#
 
9
 
1
10
require 'facter/util/macaddress'
2
11
 
3
12
Facter.add(:macaddress) do
4
 
    confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS GNU/kFreeBSD}
 
13
    confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Gentoo Ubuntu OEL OracleLinux OVS GNU/kFreeBSD}
5
14
    setcode do
6
15
        ether = []
7
 
        output = %x{/sbin/ifconfig -a}
 
16
        output = Facter::Util::Resolution.exec("/sbin/ifconfig -a")
8
17
        output.each_line do |s|
9
18
            ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
10
19
        end
11
 
        ether[0]
 
20
        Facter::Util::Macaddress.standardize(ether[0])
 
21
    end
 
22
end
 
23
 
 
24
Facter.add(:macaddress) do
 
25
    confine :operatingsystem => "Solaris"
 
26
    setcode do
 
27
        ether = []
 
28
        output = Facter::Util::Resolution.exec("/usr/bin/netstat -np")
 
29
        output.each_line do |s|
 
30
            ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/
 
31
        end
 
32
        Facter::Util::Macaddress.standardize(ether[0])
12
33
    end
13
34
end
14
35
 
16
37
    confine :operatingsystem => %w{FreeBSD OpenBSD}
17
38
    setcode do
18
39
    ether = []
19
 
        output = %x{/sbin/ifconfig}
 
40
        output = Facter::Util::Resolution.exec("/sbin/ifconfig")
20
41
        output.each_line do |s|
21
42
            if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
22
43
                ether.push($1)
23
44
            end
24
45
        end
25
 
        ether[0]
 
46
        Facter::Util::Macaddress.standardize(ether[0])
26
47
    end
27
48
end
28
49
 
50
71
                end
51
72
            end
52
73
        end
53
 
        ether[0]
 
74
        Facter::Util::Macaddress.standardize(ether[0])
54
75
    end
55
76
end
56
77
 
57
78
Facter.add(:macaddress) do
58
 
    confine :kernel => %w(windows)
59
 
    setcode do
60
 
        require 'win32ole'
61
 
        require 'socket'
62
 
 
63
 
        ether = nil
64
 
        host = Socket.gethostname
65
 
        connect_string = "winmgmts://#{host}/root/cimv2"
66
 
 
67
 
        wmi = WIN32OLE.connect(connect_string)
68
 
 
69
 
        query = %Q{
70
 
          select *
71
 
          from Win32_NetworkAdapterConfiguration
72
 
          where IPEnabled = True
73
 
        }
74
 
 
75
 
        wmi.ExecQuery(query).each{ |nic|
76
 
          ether = nic.MacAddress
77
 
          break
78
 
        }
79
 
        
80
 
        ether
81
 
    end
 
79
  confine :kernel => %w(windows)
 
80
  setcode do
 
81
    Facter::Util::Macaddress::Windows.macaddress
 
82
  end
82
83
end