Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-cloud / recipes-support / facter / files / 0005-Hardcode-ipaddress-fact-to-localhost.patch
1 From af1818469ed789bad373e6c0f8d29669acc39669 Mon Sep 17 00:00:00 2001
2 From: Don Penney <don.penney@windriver.com>
3 Date: Thu, 26 Oct 2017 10:44:20 -0400
4 Subject: [PATCH] Hardcode ipaddress fact to localhost
5
6 ---
7  lib/facter/ipaddress.rb | 163 +-----------------------------------------------
8  1 file changed, 2 insertions(+), 161 deletions(-)
9
10 diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
11 index 6179a4d..4c54791 100644
12 --- a/lib/facter/ipaddress.rb
13 +++ b/lib/facter/ipaddress.rb
14 @@ -1,169 +1,10 @@
15  # Fact: ipaddress
16  #
17 -# Purpose: Return the main IP address for a host.
18 +# To avoid potential timeouts with this fact, just return 127.0.0.1 always
19  #
20 -# Resolution:
21 -#   On the Unixes does an ifconfig, and returns the first non 127.0.0.0/8
22 -#   subnetted IP it finds.
23 -#   On Windows, it attempts to use the socket library and resolve the machine's
24 -#   hostname via DNS.
25 -#
26 -#   On LDAP based hosts it tries to use either the win32/resolv library to
27 -#   resolve the hostname to an IP address, or on Unix, it uses the resolv
28 -#   library.
29 -#
30 -#   As a fall back for undefined systems, it tries to run the "host" command to
31 -#   resolve the machine's hostname using the system DNS.
32 -#
33 -# Caveats:
34 -#   DNS resolution relies on working DNS infrastructure and resolvers on the
35 -#   host system.
36 -#   The ifconfig parsing purely takes the first IP address it finds without any
37 -#   checking this is a useful IP address.
38 -#
39 -
40 -require 'facter/util/ip'
41 -
42 -Facter.add(:ipaddress) do
43 -  confine :kernel => :linux
44 -  setcode do
45 -    ip = nil
46 -    output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"])
47 -    if output
48 -      regexp = /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
49 -      output.split("\n").each do |line|
50 -        match = regexp.match(line)
51 -        if match and not /^127\./.match(match[1])
52 -          ip = match[1]
53 -          break
54 -        end
55 -      end
56 -    end
57 -    ip
58 -  end
59 -end
60 -
61 -Facter.add(:ipaddress) do
62 -  confine :kernel => %w{FreeBSD OpenBSD Darwin DragonFly}
63 -  setcode do
64 -    ip = nil
65 -    output = Facter::Util::IP.exec_ifconfig
66 -
67 -    output.split(/^\S/).each do |str|
68 -      if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
69 -        tmp = $1
70 -        unless tmp =~ /^127\./
71 -          ip = tmp
72 -          break
73 -        end
74 -      end
75 -    end
76 -
77 -    ip
78 -  end
79 -end
80  
81  Facter.add(:ipaddress) do
82 -  confine :kernel => %w{NetBSD SunOS}
83 -  setcode do
84 -    ip = nil
85 -    output = Facter::Util::IP.exec_ifconfig(["-a"])
86 -
87 -    output.split(/^\S/).each do |str|
88 -      if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
89 -        tmp = $1
90 -        unless tmp =~ /^127\./ or tmp == "0.0.0.0"
91 -          ip = tmp
92 -          break
93 -        end
94 -      end
95 -    end
96 -
97 -    ip
98 -  end
99 -end
100 -
101 -Facter.add(:ipaddress) do
102 -  confine :kernel => %w{AIX}
103 -  setcode do
104 -    ip = nil
105 -
106 -    default_interface = Facter::Util::IP.exec_netstat(["-rn | grep default | awk '{ print $6 }'"])
107 -    output = Facter::Util::IP.exec_ifconfig([default_interface])
108 -
109 -    output.split(/^\S/).each do |str|
110 -      if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
111 -        ip = $1
112 -      end
113 -    end
114 -
115 -    ip
116 -  end
117 -end
118 -
119 -Facter.add(:ipaddress) do
120 -  confine :kernel => %w{windows}
121 -  setcode do
122 -    require 'facter/util/ip/windows'
123 -    ipaddr = nil
124 -
125 -    adapters = Facter::Util::IP::Windows.get_preferred_ipv4_adapters
126 -    adapters.find do |nic|
127 -      nic.IPAddress.any? do |addr|
128 -        ipaddr = addr if Facter::Util::IP::Windows.valid_ipv4_address?(addr)
129 -        ipaddr
130 -      end
131 -    end
132 -
133 -    ipaddr
134 -  end
135 -end
136 -
137 -Facter.add(:ipaddress, :timeout => 2) do
138 -  setcode do
139 -    if Facter.value(:kernel) == 'windows'
140 -      require 'win32/resolv'
141 -    else
142 -      require 'resolv'
143 -    end
144 -
145 -    begin
146 -      if hostname = Facter.value(:hostname)
147 -        if Facter.value(:kernel) == 'windows'
148 -          ip = Win32::Resolv.get_resolv_info.last[0]
149 -        else
150 -          ip = Resolv.getaddress(hostname)
151 -        end
152 -        unless ip == "127.0.0.1"
153 -          ip
154 -        end
155 -      else
156 -        nil
157 -      end
158 -    rescue Resolv::ResolvError
159 -      nil
160 -    rescue NoMethodError # i think this is a bug in resolv.rb?
161 -      nil
162 -    end
163 -  end
164 -end
165 -
166 -Facter.add(:ipaddress, :timeout => 2) do
167    setcode do
168 -    if hostname = Facter.value(:hostname)
169 -      # we need Hostname to exist for this to work
170 -      host = nil
171 -      if host = Facter::Core::Execution.execute("host #{hostname}")
172 -        list = host.chomp.split(/\s/)
173 -        if defined? list[-1] and
174 -          list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
175 -          list[-1]
176 -        end
177 -      else
178 -        nil
179 -      end
180 -    else
181 -      nil
182 -    end
183 +    "127.0.0.1"
184    end
185  end
186 -- 
187 1.8.3.1
188