View | Details | Raw Unified | Return to bug 190796 | Differences between
and this patch

Collapse All | Expand All

(-)rubygem-facter/files/patch-lib__facter__interfaces.rb (+20 lines)
Line 0 Link Here
1
--- lib/facter/interfaces.rb.orig	2014-06-08 11:05:48.000000000 -0500
2
+++ lib/facter/interfaces.rb	2014-06-08 11:06:21.000000000 -0500
3
@@ -39,3 +39,17 @@
4
     end
5
   end
6
 end
7
+
8
+# Get the firs 10 aliases on *BSD - however there could be more, just don't support them
9
+# as it pushes up execution time
10
+Facter::Util::IP.get_interfaces.each do |interface|
11
+  %w{ipaddress ipaddress6 netmask}.each do |label|
12
+    (0..Facter::Util::IP.get_alias_no(interface, label)).each do |a|
13
+      Facter.add(label + "_" + Facter::Util::IP.alphafy(interface) + "_alias#{a}") do
14
+        setcode do
15
+          Facter::Util::IP.get_interface_value(interface, label, a)
16
+        end
17
+      end
18
+    end
19
+  end
20
+end
(-)rubygem-facter/files/patch-lib__facter__util__ip.rb (+85 lines)
Line 0 Link Here
1
--- lib/facter/util/ip.rb.orig	2014-07-16 14:14:07.291250019 +0000
2
+++ lib/facter/util/ip.rb	2014-07-16 14:30:20.549088658 +0000
3
@@ -206,11 +206,13 @@
4
   # @param label [String] the attribute of the interface to obtain a value for,
5
   # e.g. "netmask" or "ipaddress"
6
   #
7
+  # @param intalias [Integer] the alias number to obtain a value for
8
+  #
9
   # @api private
10
   #
11
   # @return [String] representing the requested value.  An empty array is
12
   # returned if the kernel is not supported by the REGEX_MAP constant.
13
-  def self.get_interface_value(interface, label)
14
+  def self.get_interface_value(interface, label, intalias = -1)
15
     if Facter.value(:kernel) == 'windows'
16
       require 'facter/util/ip/windows'
17
       return Facter::Util::IP::Windows.value_for_interface_and_label(interface, label)
18
@@ -252,12 +254,66 @@
19
       end
20
 
21
       if tmp1
22
-        value = tmp1.shift
23
+        (-1..intalias).each do |i|
24
+          value = tmp1.shift
25
+        end
26
+        value
27
       end
28
     end
29
   end
30
 
31
   ##
32
+  # get_alias_no obtains alias count for a specified interface and label
33
+  #
34
+  # @param interface [String] the interface identifier, e.g. "eth0" or "bond0"
35
+  #
36
+  # @param label [String] the attribute of the interface to obtain a value for,
37
+  # e.g. "netmask" or "ipaddress" (note eg. ipaddress and ipaddress6 can have different
38
+  # number of aliases, so label does make sense here)
39
+  #
40
+  # @api private
41
+  #
42
+  # @return [Integer] representing the requested value.  0 is returned if the
43
+  # kernel is not supported by the REGEX_MAP constant and on Windows.
44
+  def self.get_alias_no(interface, label)
45
+    if Facter.value(:kernel) == 'windows'
46
+      # No handling of aliases in util/ip/windows as yet
47
+      return 0
48
+    end
49
+
50
+    tmp1 = []
51
+
52
+    kernel = Facter.value(:kernel).downcase.to_sym
53
+
54
+    # If it's not directly in the map or aliased in the map, then we don't know how to deal with it.
55
+    unless map = REGEX_MAP[kernel] || REGEX_MAP.values.find { |tmp| tmp[:aliases] and tmp[:aliases].include?(kernel) }
56
+      return 0
57
+    end
58
+
59
+    # Pull the correct regex out of the map.
60
+    regex = map[label.to_sym]
61
+
62
+    output_int = get_output_for_interface_and_label(interface, label)
63
+
64
+    output_int.each_line do |s|
65
+      if s =~ regex
66
+        value = $1
67
+          if label == 'netmask' && convert_from_hex?(kernel)
68
+            value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
69
+          end
70
+        tmp1.push(value)
71
+      end
72
+    end
73
+
74
+    if tmp1
75
+      value = tmp1.length
76
+    else
77
+      value = 0
78
+    end
79
+    value
80
+  end
81
+ 
82
+  ##
83
   # read_proc_net_bonding is a seam method for mocking purposes.
84
   #
85
   # @param path [String] representing the path to read, e.g. "/proc/net/bonding/bond0"

Return to bug 190796