facter 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (55) hide show
  1. data/CHANGELOG +42 -0
  2. data/COPYING +0 -458
  3. data/LICENSE +670 -13
  4. data/Rakefile +54 -10
  5. data/bin/facter +6 -2
  6. data/conf/osx/createpackage.sh +2 -1
  7. data/conf/osx/preflight +2 -1
  8. data/conf/redhat/facter.spec +25 -9
  9. data/install.rb +0 -0
  10. data/lib/facter.rb +6 -6
  11. data/lib/facter/Cfkey.rb +2 -2
  12. data/lib/facter/domain.rb +21 -52
  13. data/lib/facter/fqdn.rb +2 -1
  14. data/lib/facter/hardwareisa.rb +1 -1
  15. data/lib/facter/id.rb +12 -1
  16. data/lib/facter/interfaces.rb +32 -0
  17. data/lib/facter/ipaddress.rb +1 -1
  18. data/lib/facter/kernelrelease.rb +2 -2
  19. data/lib/facter/kernelversion.rb +4 -4
  20. data/lib/facter/lsb.rb +1 -1
  21. data/lib/facter/lsbmajdistrelease.rb +1 -1
  22. data/lib/facter/macaddress.rb +27 -27
  23. data/lib/facter/macosx.rb +3 -3
  24. data/lib/facter/manufacturer.rb +11 -2
  25. data/lib/facter/network.rb +10 -0
  26. data/lib/facter/operatingsystem.rb +4 -0
  27. data/lib/facter/operatingsystemrelease.rb +12 -15
  28. data/lib/facter/processor.rb +1 -1
  29. data/lib/facter/puppetversion.rb +2 -2
  30. data/lib/facter/uniqueid.rb +1 -1
  31. data/lib/facter/uptime.rb +20 -0
  32. data/lib/facter/util/fact.rb +1 -1
  33. data/lib/facter/util/ip.rb +134 -66
  34. data/lib/facter/util/macosx.rb +43 -30
  35. data/lib/facter/util/manufacturer.rb +13 -6
  36. data/lib/facter/util/netmask.rb +21 -23
  37. data/lib/facter/util/plist.rb +1 -1
  38. data/lib/facter/util/uptime.rb +32 -0
  39. data/lib/facter/virtual.rb +66 -53
  40. data/spec/integration/facter.rb +0 -0
  41. data/spec/spec_helper.rb +1 -10
  42. data/spec/unit/data/6.0-STABLE_FreeBSD_ifconfig +12 -0
  43. data/spec/unit/data/Mac_OS_X_10.5.5_ifconfig +26 -0
  44. data/spec/unit/data/darwin_ifconfig_single_interface +6 -0
  45. data/spec/unit/facter.rb +1 -1
  46. data/spec/unit/interfaces.rb +19 -0
  47. data/spec/unit/util/collection.rb +2 -2
  48. data/spec/unit/util/confine.rb +0 -0
  49. data/spec/unit/util/fact.rb +0 -0
  50. data/spec/unit/util/ip.rb +65 -9
  51. data/spec/unit/util/loader.rb +1 -1
  52. data/spec/unit/util/macosx.rb +47 -0
  53. data/spec/unit/util/resolution.rb +0 -0
  54. metadata +12 -4
  55. data/lib/facter/ipmess.rb +0 -46
@@ -1,5 +1,5 @@
1
1
  Facter.add("kernelversion") do
2
- setcode do
3
- Facter['kernelrelease'].value.split('-')[0]
4
- end
5
- end
2
+ setcode do
3
+ Facter['kernelrelease'].value.split('-')[0]
4
+ end
5
+ end
@@ -27,7 +27,7 @@
27
27
  @@lsbtime = Time.now
28
28
  @@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
29
29
  end
30
-
30
+
31
31
  if pattern.match(@@lsbdata)
32
32
  $1
33
33
  else
@@ -3,7 +3,7 @@
3
3
  require 'facter'
4
4
 
5
5
  Facter.add("lsbmajdistrelease") do
6
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
6
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo}
7
7
  setcode do
8
8
  if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
9
9
  result=$1
@@ -1,11 +1,11 @@
1
1
  Facter.add(:macaddress) do
2
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo Ubuntu}
2
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu}
3
3
  setcode do
4
4
  ether = []
5
5
  output = %x{/sbin/ifconfig -a}
6
- output.each {|s|
7
- 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})/
8
- }
6
+ output.each do |s|
7
+ 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})/
8
+ end
9
9
  ether[0]
10
10
  end
11
11
  end
@@ -15,11 +15,11 @@ Facter.add(:macaddress) do
15
15
  setcode do
16
16
  ether = []
17
17
  output = %x{/sbin/ifconfig}
18
- output.each {|s|
19
- if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
20
- ether.push($1)
21
- end
22
- }
18
+ output.each do |s|
19
+ if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
20
+ ether.push($1)
21
+ end
22
+ end
23
23
  ether[0]
24
24
  end
25
25
  end
@@ -30,12 +30,12 @@ Facter.add(:macaddress) do
30
30
  ether = nil
31
31
  output = %x{/sbin/ifconfig}
32
32
 
33
- output.split(/^\S/).each { |str|
33
+ output.split(/^\S/).each do |str|
34
34
  if str =~ /10baseT/ # we're wired
35
35
  str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
36
36
  ether = $1
37
37
  end
38
- }
38
+ end
39
39
 
40
40
  ether
41
41
  end
@@ -47,19 +47,19 @@ Facter.add(:macaddress) do
47
47
  ether = []
48
48
  ip = nil
49
49
  output = %x{/usr/sbin/ifconfig -a}
50
- output.each { |str|
50
+ output.each do |str|
51
51
  if str =~ /([a-z]+\d+): flags=/
52
52
  devname = $1
53
53
  unless devname =~ /lo0/
54
- output2 = %x{/usr/bin/entstat #{devname}}
55
- output2.each { |str2|
56
- if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
57
- ether.push($1)
58
- end
59
- }
54
+ output2 = %x{/usr/bin/entstat #{devname}}
55
+ output2.each do |str2|
56
+ if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
57
+ ether.push($1)
58
+ end
59
+ end
60
60
  end
61
61
  end
62
- }
62
+ end
63
63
  ether[0]
64
64
  end
65
65
  end
@@ -67,13 +67,13 @@ end
67
67
  Facter.add(:macaddress) do
68
68
  confine :kernel => %w(windows)
69
69
  setcode do
70
- ether = []
71
- output = %x{ipconfig /all}
72
- output.split(/\r\n/).each do |str|
73
- if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
74
- ether.push($1.gsub(/-/, ":"))
75
- end
76
- end
77
- ether[0]
70
+ ether = []
71
+ output = %x{ipconfig /all}
72
+ output.split(/\r\n/).each do |str|
73
+ if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
74
+ ether.push($1.gsub(/-/, ":"))
75
+ end
76
+ end
77
+ ether[0]
78
78
  end
79
79
  end
@@ -25,7 +25,7 @@
25
25
  require 'facter/util/macosx'
26
26
 
27
27
  if Facter.value(:kernel) == "Darwin"
28
- Facter::Macosx.hardware_overview.each do |fact, value|
28
+ Facter::Util::Macosx.hardware_overview.each do |fact, value|
29
29
  Facter.add("sp_#{fact}") do
30
30
  confine :kernel => :darwin
31
31
  setcode do
@@ -34,7 +34,7 @@ if Facter.value(:kernel) == "Darwin"
34
34
  end
35
35
  end
36
36
 
37
- Facter::Macosx.os_overview.each do |fact, value|
37
+ Facter::Util::Macosx.os_overview.each do |fact, value|
38
38
  Facter.add("sp_#{fact}") do
39
39
  confine :kernel => :darwin
40
40
  setcode do
@@ -43,7 +43,7 @@ if Facter.value(:kernel) == "Darwin"
43
43
  end
44
44
  end
45
45
 
46
- Facter::Macosx.sw_vers.each do |fact, value|
46
+ Facter::Util::Macosx.sw_vers.each do |fact, value|
47
47
  Facter.add(fact) do
48
48
  confine :kernel => :darwin
49
49
  setcode do
@@ -5,6 +5,15 @@
5
5
 
6
6
  require 'facter/util/manufacturer'
7
7
 
8
- query = { 'System Information' => [ 'Manufacturer:', 'Product Name:' , 'Serial Number:'], 'Chassis Information' => 'Type:'}
8
+ query = {
9
+ '[Ss]ystem [Ii]nformation' => [
10
+ { 'Manufacturer:' => 'manufacturer' },
11
+ { 'Product(?: Name)?:' => 'productname' },
12
+ { 'Serial Number:' => 'serialnumber' }
13
+ ],
14
+ '(Chassis Information|system enclosure or chassis)' => [
15
+ { '(?:Chassis )?Type:' => 'type' }
16
+ ]
17
+ }
9
18
 
10
- Facter::Manufacturer.dmi_find_system_info(query)
19
+ Facter::Manufacturer.dmi_find_system_info(query)
@@ -0,0 +1,10 @@
1
+ require 'facter/util/ip'
2
+
3
+ Facter::Util::IP.get_interfaces.each do |interface|
4
+
5
+ Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do
6
+ setcode do
7
+ Facter::Util::IP.get_network_value(interface)
8
+ end
9
+ end
10
+ end
@@ -18,6 +18,8 @@ Facter.add(:operatingsystem) do
18
18
  "Mandriva"
19
19
  elsif FileTest.exists?("/etc/mandrake-release")
20
20
  "Mandrake"
21
+ elsif FileTest.exists?("/etc/arch-release")
22
+ "Archlinux"
21
23
  elsif FileTest.exists?("/etc/redhat-release")
22
24
  txt = File.read("/etc/redhat-release")
23
25
  if txt =~ /centos/i
@@ -29,6 +31,8 @@ Facter.add(:operatingsystem) do
29
31
  txt = File.read("/etc/SuSE-release")
30
32
  if txt =~ /^SUSE LINUX Enterprise Server/i
31
33
  "SLES"
34
+ elsif txt =~ /^openSUSE/i
35
+ "OpenSuSE"
32
36
  else
33
37
  "SuSE"
34
38
  end
@@ -29,11 +29,11 @@ end
29
29
  Facter.add(:operatingsystemrelease) do
30
30
  confine :operatingsystem => %w{CentOS}
31
31
  setcode do
32
- centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \((Branch|Final)\)//' /etc/redhat-release")
32
+ centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \((Branch|Final)\)//' /etc/redhat-release")
33
33
  if centos_release =~ /5/
34
- release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
34
+ release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
35
35
  else
36
- release = centos_release
36
+ release = centos_release
37
37
  end
38
38
  end
39
39
  end
@@ -42,29 +42,31 @@ Facter.add(:operatingsystemrelease) do
42
42
  confine :operatingsystem => %w{Debian}
43
43
  setcode do
44
44
  release = Facter::Util::Resolution.exec('cat /etc/debian_version')
45
- end
45
+ end
46
46
  end
47
47
 
48
48
  Facter.add(:operatingsystemrelease) do
49
49
  confine :operatingsystem => %w{Ubuntu}
50
50
  setcode do
51
51
  release = Facter::Util::Resolution.exec('cat /etc/issue')
52
- if release =~ /Ubuntu (\d+.\d+)/
53
- $1
54
- end
52
+ if release =~ /Ubuntu (\d+.\d+)/
53
+ $1
54
+ end
55
55
  end
56
56
  end
57
57
 
58
58
  Facter.add(:operatingsystemrelease) do
59
- confine :operatingsystem => %w{SLES}
59
+ confine :operatingsystem => %w{SLES OpenSuSE}
60
60
  setcode do
61
61
  releasefile = Facter::Util::Resolution.exec('cat /etc/SuSE-release')
62
62
  if releasefile =~ /^VERSION\s*=\s*(\d+)/
63
63
  releasemajor = $1
64
64
  if releasefile =~ /^PATCHLEVEL\s*=\s*(\d+)/
65
65
  releaseminor = $1
66
+ elsif releasefile =~ /^VERSION\s=.*.(\d+)/
67
+ releaseminor = $1
66
68
  else
67
- releaseminor = 0
69
+ releaseminor = "0"
68
70
  end
69
71
  releasemajor + "." + releaseminor
70
72
  else
@@ -76,12 +78,7 @@ end
76
78
  Facter.add(:operatingsystemrelease) do
77
79
  confine :operatingsystem => %w{Solaris}
78
80
  setcode do
79
- full_release = File.readlines("/etc/release").to_s.match(/Solaris \w+ [\w\/]+ ([^_]+_[^_]+)/).to_a.last.chomp("wos")
80
- if full_release =~ /^s(\d+)\w(_\w\d)+/
81
- $1 + $2
82
- else
83
- full_release
84
- end
81
+ release = Facter::Util::Resolution.exec('uname -v')
85
82
  end
86
83
  end
87
84
 
@@ -46,7 +46,7 @@ if Facter.value(:kernel) == "AIX"
46
46
  procs.each do |proc|
47
47
  if proc =~ /^proc(\d+)/
48
48
  processor_num = $1.to_i
49
- # Not retrieving the frequency since AIX 4.3.3 doesn't support the
49
+ # Not retrieving the frequency since AIX 4.3.3 doesn't support the
50
50
  # attribute and some people still use the OS.
51
51
  proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a type')
52
52
  if proctype =~ /^type\s+(\S+)\s+/
@@ -1,10 +1,10 @@
1
1
  Facter.add(:puppetversion) do
2
- setcode {
2
+ setcode do
3
3
  begin
4
4
  require 'puppet'
5
5
  Puppet::PUPPETVERSION.to_s
6
6
  rescue LoadError
7
7
  nil
8
8
  end
9
- }
9
+ end
10
10
  end
@@ -1,4 +1,4 @@
1
1
  Facter.add(:uniqueid) do
2
2
  setcode 'hostid', '/bin/sh'
3
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo AIX}
3
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX}
4
4
  end
@@ -0,0 +1,20 @@
1
+ require 'facter/util/uptime'
2
+
3
+ Facter.add(:uptime) do
4
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX}
5
+ setcode do
6
+ Facter::Util::Uptime.get_uptime_simple
7
+ end
8
+ end
9
+
10
+ if FileTest.exists?("/proc/uptime")
11
+ uptime = Facter::Util::Uptime.get_uptime
12
+
13
+ %w{days hours seconds}.each do |label|
14
+ Facter.add("uptime_" + label) do
15
+ setcode do
16
+ Facter::Util::Uptime.get_uptime_period(uptime, label)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -102,7 +102,7 @@ class Facter::Util::Fact
102
102
  def searching
103
103
  if searching?
104
104
  Facter.debug "Caught recursion on %s" % @name
105
-
105
+
106
106
  # return a cached value if we've got it
107
107
  if @value
108
108
  return @value
@@ -1,27 +1,69 @@
1
- module Facter::IPAddress
2
-
1
+ # A base module for collecting IP-related
2
+ # information from all kinds of platforms.
3
+ module Facter::Util::IP
4
+ # A map of all the different regexes that work for
5
+ # a given platform or set of platforms.
6
+ REGEX_MAP = {
7
+ :linux => {
8
+ :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
9
+ :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
10
+ :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
11
+ },
12
+ :bsd => {
13
+ :aliases => [:openbsd, :netbsd, :freebsd, :darwin],
14
+ :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
15
+ :macaddress => /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/,
16
+ :netmask => /netmask\s+0x(\w{8})/
17
+ },
18
+ :sunos => {
19
+ :addr => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
20
+ :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
21
+ :netmask => /netmask\s+(\w{8})/
22
+ }
23
+ }
24
+
25
+ # Convert an interface name into purely alpha characters.
26
+ def self.alphafy(interface)
27
+ interface.gsub(/[:.]/, '_')
28
+ end
29
+
30
+ def self.convert_from_hex?(kernel)
31
+ kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin]
32
+ kernels_to_convert.include?(kernel)
33
+ end
34
+
35
+ def self.supported_platforms
36
+ REGEX_MAP.inject([]) do |result, tmp|
37
+ key, map = tmp
38
+ if map[:aliases]
39
+ result += map[:aliases]
40
+ else
41
+ result << key
42
+ end
43
+ result
44
+ end
45
+ end
46
+
3
47
  def self.get_interfaces
4
-
5
- int = nil
6
-
7
- output = Facter::IPAddress.get_all_interface_output()
8
-
9
- # We get lots of warnings on platforms that don't get an output
10
- # made.
11
- if output
12
- int = output.scan(/^\w+[.:]?\d+/)
13
- else
14
- []
15
- end
16
-
48
+ int = nil
49
+
50
+ output = Facter::Util::IP.get_all_interface_output()
51
+
52
+ # We get lots of warnings on platforms that don't get an output
53
+ # made.
54
+ if output
55
+ int = output.scan(/^\w+[.:]?\d+/)
56
+ else
57
+ []
58
+ end
17
59
  end
18
60
 
19
61
  def self.get_all_interface_output
20
62
  case Facter.value(:kernel)
21
- when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
22
- output = %x{/sbin/ifconfig -a}
23
- when 'SunOS'
24
- output = %x{/usr/sbin/ifconfig -a}
63
+ when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin'
64
+ output = %x{/sbin/ifconfig -a}
65
+ when 'SunOS'
66
+ output = %x{/usr/sbin/ifconfig -a}
25
67
  end
26
68
  output
27
69
  end
@@ -29,60 +71,86 @@ module Facter::IPAddress
29
71
  def self.get_single_interface_output(interface)
30
72
  output = ""
31
73
  case Facter.value(:kernel)
32
- when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
33
- output = %x{/sbin/ifconfig #{interface}}
34
- when 'SunOS'
74
+ when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin'
75
+ output = %x{/sbin/ifconfig #{interface}}
76
+ when 'SunOS'
35
77
  output = %x{/usr/sbin/ifconfig #{interface}}
36
78
  end
37
79
  output
38
80
  end
39
81
 
82
+ def self.get_bonding_master(interface)
83
+ if Facter.value(:kernel) != 'Linux'
84
+ return nil
85
+ end
86
+ # We need ip instead of ifconfig because it will show us
87
+ # the bonding master device.
88
+ if not FileTest.executable?("/sbin/ip")
89
+ return nil
90
+ end
91
+ regex = /SLAVE[,>].* (bond[0-9]+)/
92
+ ethbond = regex.match(%x{/sbin/ip link show #{interface}})
93
+ if ethbond
94
+ device = ethbond[1]
95
+ else
96
+ device = nil
97
+ end
98
+ device
99
+ end
100
+
40
101
 
41
102
  def self.get_interface_value(interface, label)
42
-
43
- tmp1 = []
44
-
45
- case Facter.value(:kernel)
46
- when 'Linux'
47
- addr = /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
48
- mac = /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
49
- mask = /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
50
- when 'OpenBSD', 'NetBSD', 'FreeBSD'
51
- addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
52
- mac = /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
53
- mask = /netmask\s+(\w{10})/
54
- when 'SunOS'
55
- addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
56
- mac = /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/
57
- mask = /netmask\s+(\w{8})/
103
+ tmp1 = []
104
+
105
+ kernel = Facter.value(:kernel).downcase.to_sym
106
+
107
+ # If it's not directly in the map or aliased in the map, then we don't know how to deal with it.
108
+ unless map = REGEX_MAP[kernel] || REGEX_MAP.values.find { |tmp| tmp[:aliases] and tmp[:aliases].include?(kernel) }
109
+ return []
110
+ end
111
+
112
+ # Pull the correct regex out of the map.
113
+ regex = map[label.to_sym]
114
+
115
+ # Linux changes the MAC address reported via ifconfig when an ethernet interface
116
+ # becomes a slave of a bonding device to the master MAC address.
117
+ # We have to dig a bit to get the original/real MAC address of the interface.
118
+ bonddev = get_bonding_master(interface)
119
+ if label == 'macaddress' and bonddev
120
+ bondinfo = IO.readlines("/proc/net/bonding/#{bonddev}")
121
+ hwaddrre = /^Slave Interface: #{interface}\n[^\n].+?\nPermanent HW addr: (([0-9a-fA-F]{2}:?)*)$/m
122
+ value = hwaddrre.match(bondinfo.to_s)[1].upcase
123
+ else
124
+ output_int = get_single_interface_output(interface)
125
+
126
+ if interface != "lo" && interface != "lo0"
127
+ output_int.each do |s|
128
+ if s =~ regex
129
+ value = $1
130
+ if label == 'netmask' && convert_from_hex?(kernel)
131
+ value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
132
+ end
133
+ tmp1.push(value)
134
+ end
135
+ end
136
+ end
137
+
138
+ if tmp1
139
+ value = tmp1.shift
140
+ end
141
+ end
58
142
  end
143
+
144
+ def self.get_network_value(interface)
145
+ require 'ipaddr'
59
146
 
60
- case label
61
- when 'ipaddress'
62
- regex = addr
63
- when 'macaddress'
64
- regex = mac
65
- when 'netmask'
66
- regex = mask
67
- end
68
-
69
- output_int = get_single_interface_output(interface)
70
-
71
- if interface != "lo" && interface != "lo0"
72
- output_int.each { |s|
73
- if s =~ regex
74
- value = $1
75
- if label == 'netmask' && Facter.value(:kernel) == "SunOS"
76
- value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
77
- end
78
- tmp1.push(value)
79
- end
80
- }
81
- end
82
-
83
- if tmp1
84
- value = tmp1.shift
85
- end
86
-
87
- end
147
+ ipaddress = get_interface_value(interface, "ipaddress")
148
+ netmask = get_interface_value(interface, "netmask")
149
+
150
+ if ipaddress && netmask
151
+ ip = IPAddr.new(ipaddress, Socket::AF_INET)
152
+ subnet = IPAddr.new(netmask, Socket::AF_INET)
153
+ network = ip.mask(subnet.to_s)
154
+ end
155
+ end
88
156
  end