ohai 16.17.2 → 17.0.42

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13d2f3369090412d4b03cbe4ec7cae19c4d10276d10abeb44036a98792128a5a
4
- data.tar.gz: 7f22588951efbb2f0e0585a8ed958529cb55623cefb1ab214866b1878b6d1432
3
+ metadata.gz: cdfc3193f6099ddf2aadfd2469885459a9b386748db334fe88d817d7d0fa8ebf
4
+ data.tar.gz: ee7268731025ab543f38c3194e90d64dc50cde57e92b6e074b035faa46311a16
5
5
  SHA512:
6
- metadata.gz: 857f8cfd699d5c0fb424c34c935dab790202922dc1d76556aaf50ed7cb1d25286d8c28eb1c25f258b798a13beb6fd738da69a90f65e5fa06422e3ae71e9602ce
7
- data.tar.gz: 7b7a2d48a1ce3a4298fe145e088609935b99adb032f414ddc1fdac968d2111ca96e1366ede4d7e3c568d166bbe6030e9181b925cc37fcf64722409a20bd9945c
6
+ metadata.gz: 0322e5ef42f16d73bad92f76d24abd28ebd0ca7cd86a9cd1f1333f345b6b49725ea7dcea5d9760ad11f9e21489e675c0d048f18aa0becd2e1c8c5b67c18e7bed
7
+ data.tar.gz: cb923703f4e7fa79533e1723366bd762f047f79c1c9abc57d12103c51eaef543c5770425de831d15e2ac00944d04757bdff55b090ade4f6fbb555540bb4e49e6
data/Gemfile CHANGED
@@ -3,20 +3,20 @@ source "https://rubygems.org"
3
3
 
4
4
  gemspec
5
5
 
6
- # pull these gems from chef-16 of chef/chef so that we're testing against what we will release
7
- gem "chef-config", git: "https://github.com/chef/chef", branch: "chef-16", glob: "chef-config/chef-config.gemspec"
8
- gem "chef-utils", git: "https://github.com/chef/chef", branch: "chef-16", glob: "chef-utils/chef-utils.gemspec"
6
+ # pull these gems from master of chef/chef so that we're testing against what we will release
7
+ gem "chef-config", git: "https://github.com/chef/chef", branch: "master", glob: "chef-config/chef-config.gemspec"
8
+ gem "chef-utils", git: "https://github.com/chef/chef", branch: "master", glob: "chef-utils/chef-utils.gemspec"
9
9
 
10
10
  # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
11
11
  group :development do
12
- gem "chefstyle", "1.6.2"
12
+ gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
13
13
  gem "ipaddr_extensions"
14
14
  gem "rake", ">= 10.1.0"
15
15
  gem "rspec-collection_matchers", "~> 1.0"
16
16
  gem "rspec-core", "~> 3.0"
17
17
  gem "rspec-expectations", "~> 3.0"
18
18
  gem "rspec-mocks", "~> 3.0"
19
- gem "rubocop-performance", "1.9.2"
19
+ gem "rubocop-performance", "1.10.2"
20
20
  gem "rubocop-rspec"
21
21
  end
22
22
 
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ # Copyright:: Copyright (c) Chef Software Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require "net/http" unless defined?(Net::HTTP)
20
+
21
+ module Ohai
22
+ module Mixin
23
+ #
24
+ # This code parses the Alibaba Instance Metadata API to provide details
25
+ # of the running instance.
26
+ #
27
+ # Note: As of 2021-02-07 there is only one API release so we're not implementing
28
+ # logic like the ec2 or azure mixins where we have to find the latest supported
29
+ # release
30
+ module AlibabaMetadata
31
+
32
+ ALI_METADATA_ADDR ||= "100.100.100.200"
33
+
34
+ def http_get(uri)
35
+ conn = Net::HTTP.start(ALI_METADATA_ADDR)
36
+ conn.read_timeout = 6
37
+ conn.keep_alive_timeout = 6
38
+ conn.get("/2016-01-01/#{uri}", { "User-Agent" => "chef-ohai/#{Ohai::VERSION}" })
39
+ end
40
+
41
+ def fetch_metadata(id = "")
42
+ response = http_get(id)
43
+ return nil unless response.code == "200"
44
+
45
+ if json?(response.body)
46
+ data = String(response.body)
47
+ parser = FFI_Yajl::Parser.new
48
+ parser.parse(data)
49
+ elsif response.body.include?("\n")
50
+ temp = {}
51
+ response.body.split("\n").each do |sub_attr|
52
+ temp[sanitize_key(sub_attr)] = fetch_metadata("#{id}/#{sub_attr}")
53
+ end
54
+ temp
55
+ else
56
+ response.body
57
+ end
58
+ end
59
+
60
+ # @param [String] data that might be JSON
61
+ #
62
+ # @return [Boolean] is the data JSON or not?
63
+ def json?(data)
64
+ data = String(data)
65
+ parser = FFI_Yajl::Parser.new
66
+ begin
67
+ parser.parse(data)
68
+ true
69
+ rescue FFI_Yajl::ParseError
70
+ false
71
+ end
72
+ end
73
+
74
+ # @param data [String]
75
+ #
76
+ # @return [Boolean] is there a trailing /?
77
+ def has_trailing_slash?(data)
78
+ !!( data =~ %r{/$} )
79
+ end
80
+
81
+ def sanitize_key(key)
82
+ key.gsub(%r{\-|/}, "_")
83
+ end
84
+ end
85
+ end
86
+ end
@@ -24,14 +24,15 @@ Ohai.plugin(:Virtualization) do
24
24
  virtualization Mash.new
25
25
 
26
26
  lpar_no, lpar_name = shell_out("uname -L").stdout.split(nil, 2)
27
+ lpar_no = lpar_no.to_i
27
28
 
28
- unless lpar_no.to_i == -1 || (lpar_no.to_i == 1 && lpar_name == "NULL")
29
+ unless lpar_no == -1 || (lpar_no == 1 && lpar_name == "NULL")
29
30
  virtualization[:lpar_no] = lpar_no
30
31
  virtualization[:lpar_name] = lpar_name
31
32
  end
32
33
 
33
- wpar_no = shell_out("uname -W").stdout.strip
34
- if wpar_no.to_i > 0
34
+ wpar_no = shell_out("uname -W").stdout.strip.to_i
35
+ if wpar_no > 0
35
36
  virtualization[:wpar_no] = wpar_no
36
37
  else
37
38
  # the below parses the output of lswpar in the long format
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ # Copyright:: Copyright (c) Chef Software Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ # How we detect Alibaba from easiest to hardest & least reliable
20
+ # 1. Ohai alibaba hint exists. This always works
21
+ # 2. DMI sys_vendor data mentions alibaba.
22
+
23
+ Ohai.plugin(:Alibaba) do
24
+ require_relative "../mixin/alibaba_metadata"
25
+ require_relative "../mixin/http_helper"
26
+
27
+ include Ohai::Mixin::AlibabaMetadata
28
+ include Ohai::Mixin::HttpHelper
29
+
30
+ provides "alibaba"
31
+
32
+ # look for alibaba string in dmi sys_vendor data within the sys tree.
33
+ # this works even if the system lacks dmidecode use by the Dmi plugin
34
+ # @return [Boolean] do we have Alibaba DMI data?
35
+ def has_ali_dmi?
36
+ if /Alibaba/.match?(file_val_if_exists("/sys/class/dmi/id/sys_vendor"))
37
+ logger.trace("Plugin Alibaba: has_ali_dmi? == true")
38
+ true
39
+ else
40
+ logger.trace("Plugin Alibaba: has_ali_dmi? == false")
41
+ false
42
+ end
43
+ end
44
+
45
+ # return the contents of a file if the file exists
46
+ # @param path[String] abs path to the file
47
+ # @return [String] contents of the file if it exists
48
+ def file_val_if_exists(path)
49
+ if file_exist?(path)
50
+ file_read(path)
51
+ end
52
+ end
53
+
54
+ # a single check that combines all the various detection methods for Alibaba
55
+ # @return [Boolean] Does the system appear to be on Alibaba
56
+ def looks_like_alibaba?
57
+ return true if hint?("alibaba") || has_ali_dmi?
58
+ end
59
+
60
+ collect_data do
61
+ if looks_like_alibaba?
62
+ logger.trace("Plugin Alibaba: looks_like_alibaba? == true")
63
+ alibaba Mash.new
64
+ fetch_metadata.each do |k, v|
65
+ alibaba[k] = v
66
+ end
67
+ else
68
+ logger.trace("Plugin Alibaba: looks_like_alibaba? == false")
69
+ false
70
+ end
71
+ end
72
+ end
@@ -85,14 +85,12 @@ Ohai.plugin(:C) do
85
85
 
86
86
  def collect_glibc
87
87
  # glibc
88
- ["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc|
89
- collect( Ohai.abs_path( glibc )) do |so|
90
- description = so.stdout.split($/).first
91
- if description =~ /(\d+\.\d+\.?\d*)/
92
- @c[:glibc] = Mash.new
93
- @c[:glibc][:version] = $1
94
- @c[:glibc][:description] = description
95
- end
88
+ collect("ldd --version") do |so|
89
+ description = so.stdout.split($/).first
90
+ if description =~ /(\d+\.\d+\.?\d*)/
91
+ @c[:glibc] = Mash.new
92
+ @c[:glibc][:version] = $1
93
+ @c[:glibc][:description] = description
96
94
  end
97
95
  end
98
96
  end
@@ -18,6 +18,7 @@
18
18
  Ohai.plugin(:Cloud) do
19
19
  provides "cloud"
20
20
 
21
+ depends "alibaba"
21
22
  depends "ec2"
22
23
  depends "gce"
23
24
  depends "rackspace"
@@ -118,7 +119,22 @@ Ohai.plugin(:Cloud) do
118
119
  end
119
120
  end
120
121
 
121
- #---------------------------------------
122
+ #--------------------------------------
123
+ # Alibaba Cloud
124
+ #--------------------------------------
125
+
126
+ def on_alibaba?
127
+ alibaba != nil
128
+ end
129
+
130
+ def get_alibaba_values
131
+ @cloud_attr_obj.add_ipv4_addr(alibaba["meta_data"]["eipv4"], :public)
132
+ @cloud_attr_obj.add_ipv4_addr(alibaba["meta_data"]["private_ipv4"], :private)
133
+ @cloud_attr_obj.local_hostname = alibaba["meta_data"]["hostname"]
134
+ @cloud_attr_obj.provider = "alibaba"
135
+ end
136
+
137
+ #--------------------------------------
122
138
  # Google Compute Engine (gce)
123
139
  #--------------------------------------
124
140
 
@@ -133,9 +149,9 @@ Ohai.plugin(:Cloud) do
133
149
  end
134
150
  end.flatten.compact
135
151
 
136
- private_ips = gce["instance"]["networkInterfaces"].collect do |interface|
152
+ private_ips = gce["instance"]["networkInterfaces"].filter_map do |interface|
137
153
  interface["ip"]
138
- end.compact
154
+ end
139
155
 
140
156
  public_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :public) }
141
157
  private_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :private) }
@@ -334,6 +350,7 @@ Ohai.plugin(:Cloud) do
334
350
  get_azure_values if on_azure?
335
351
  get_digital_ocean_values if on_digital_ocean?
336
352
  get_softlayer_values if on_softlayer?
353
+ get_alibaba_values if on_alibaba?
337
354
 
338
355
  cloud @cloud_attr_obj.cloud_mash
339
356
  end
@@ -9,6 +9,7 @@
9
9
  # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
10
10
  # Author:: Isa Farnik (<isa@chef.io>)
11
11
  # Author:: Doug MacEachern <dougm@vmware.com>
12
+ # Author:: Lance Albertson <lance@osuosl.org>
12
13
  # Copyright:: Copyright (c) Chef Software Inc.
13
14
  # License:: Apache License, Version 2.0
14
15
  #
@@ -46,13 +47,213 @@ Ohai.plugin(:CPU) do
46
47
  cpuinfo
47
48
  end
48
49
 
49
- collect_data(:linux) do
50
+ # Convert a string that looks like range of CPUs to an array
51
+ # Given the following range: 1-7
52
+ # Convert it into an array: [1, 2, 3, 4, 5, 6, 7]
53
+ def range_str_to_a(range)
54
+ range.split(",").each_with_object([]) do |cpu, arr|
55
+ if /\d+-\d+/.match?(cpu.to_s)
56
+ arr << Range.new(*cpu.split("-").map(&:to_i)).to_a
57
+ else
58
+ arr << cpu.to_i
59
+ end
60
+ end.flatten
61
+ end
62
+
63
+ def parse_lscpu(cpu_info)
64
+ lscpu_info = Mash.new
65
+ begin
66
+ so = shell_out("lscpu")
67
+ cpu_cores = shell_out("lscpu -p=CPU,CORE,SOCKET")
68
+ if so.exitstatus == 0 && cpu_cores.exitstatus == 0
69
+ lscpu_info[:numa_node_cpus] = Mash.new
70
+ lscpu_info[:vulnerability] = Mash.new
71
+ so.stdout.each_line do |line|
72
+ case line
73
+ when /^Architecture:\s+(.+)/
74
+ lscpu_info[:architecture] = $1.to_s
75
+ when /^CPU op-mode\(s\):\s+(.+)/
76
+ lscpu_info[:cpu_opmodes] = $1.split(", ")
77
+ when /^Byte Order:\s+(.+)/
78
+ lscpu_info[:byte_order] = $1.downcase
79
+ when /^Address sizes:\s+(.+)/
80
+ lscpu_info[:address_sizes] = $1.split(", ")
81
+ when /^CPU\(s\):\s+(.+)/
82
+ lscpu_info[:cpus] = $1.to_i
83
+ when /^On-line CPU\(s\) list:\s+(.+)/
84
+ cpu_range = range_str_to_a($1)
85
+ if cpu_range == [0]
86
+ lscpu_info[:cpus_online] = 0
87
+ else
88
+ lscpu_info[:cpus_online] = cpu_range.length
89
+ end
90
+ when /^Off-line CPU\(s\) list:\s+(.+)/
91
+ cpu_range = range_str_to_a($1)
92
+ if cpu_range == [0]
93
+ lscpu_info[:cpus_offline] = 0
94
+ else
95
+ lscpu_info[:cpus_offline] = cpu_range.length
96
+ end
97
+ when /^Thread\(s\) per core:\s+(.+)/ # http://rubular.com/r/lOw2pRrw1q
98
+ lscpu_info[:threads_per_core] = $1.to_i
99
+ when /^Core\(s\) per socket:\s+(.+)/ # http://rubular.com/r/lOw2pRrw1q
100
+ lscpu_info[:cores_per_socket] = $1.to_i
101
+ when /^Socket\(s\):\s+(.+)/ # http://rubular.com/r/DIzmPtJFvK
102
+ lscpu_info[:sockets] = $1.to_i
103
+ when /^Socket\(s\) per book:\s+(.+)/
104
+ lscpu_info[:sockets_per_book] = $1.to_i
105
+ when /^Book\(s\) per drawer:\s+(.+)/
106
+ lscpu_info[:books_per_drawer] = $1.to_i
107
+ when /^Drawer\(s\):\s+(.+)/
108
+ lscpu_info[:drawers] = $1.to_i
109
+ when /^NUMA node\(s\):\s+(.+)/
110
+ lscpu_info[:numa_nodes] = $1.to_i
111
+ when /^Vendor ID:\s+(.+)/
112
+ lscpu_info[:vendor_id] = $1
113
+ when /^Machine type:\s+(.+)/
114
+ lscpu_info[:machine_type] = $1
115
+ when /^CPU family:\s+(.+)/
116
+ lscpu_info[:family] = $1
117
+ when /^Model:\s+(.+)/
118
+ lscpu_info[:model] = $1
119
+ when /^Model name:\s+(.+)/
120
+ lscpu_info[:model_name] = $1
121
+ when /^Stepping:\s+(.+)/
122
+ lscpu_info[:stepping] = $1
123
+ when /^CPU MHz:\s+(.+)/
124
+ lscpu_info[:mhz] = $1
125
+ when /^CPU static MHz:\s+(.+)/
126
+ lscpu_info[:mhz] = $1
127
+ when /^CPU max MHz:\s+(.+)/
128
+ lscpu_info[:mhz_max] = $1
129
+ when /^CPU min MHz:\s+(.+)/
130
+ lscpu_info[:mhz_min] = $1
131
+ when /^CPU dynamic MHz:\s+(.+)/
132
+ lscpu_info[:mhz_dynamic] = $1
133
+ when /^BogoMIPS:\s+(.+)/
134
+ lscpu_info[:bogomips] = $1
135
+ when /^Virtualization:\s+(.+)/
136
+ lscpu_info[:virtualization] = $1
137
+ when /^Virtualization type:\s+(.+)/
138
+ lscpu_info[:virtualization_type] = $1
139
+ when /^Hypervisor vendor:\s+(.+)/
140
+ lscpu_info[:hypervisor_vendor] = $1
141
+ when /^Dispatching mode:\s+(.+)/
142
+ lscpu_info[:dispatching_mode] = $1
143
+ when /^L1d cache:\s+(.+)/
144
+ lscpu_info[:l1d_cache] = $1
145
+ when /^L1i cache:\s+(.+)/
146
+ lscpu_info[:l1i_cache] = $1
147
+ when /^L2 cache:\s+(.+)/
148
+ lscpu_info[:l2_cache] = $1
149
+ when /^L2d cache:\s+(.+)/
150
+ lscpu_info[:l2d_cache] = $1
151
+ when /^L2i cache:\s+(.+)/
152
+ lscpu_info[:l2i_cache] = $1
153
+ when /^L3 cache:\s+(.+)/
154
+ lscpu_info[:l3_cache] = $1
155
+ when /^L4 cache:\s+(.+)/
156
+ lscpu_info[:l4_cache] = $1
157
+ when /^NUMA node(\d+) CPU\(s\):\s+(.+)/
158
+ numa_node = $1
159
+ cpus = $2
160
+ lscpu_info[:numa_node_cpus][numa_node] = range_str_to_a(cpus)
161
+ when /^Vulnerability (.+?):\s+(.+)/ # https://rubular.com/r/aKtSD1ypUlKbGm
162
+ name = $1.strip.downcase.tr(" ", "_")
163
+ description = $2.strip
164
+ lscpu_info[:vulnerability][name] = Mash.new
165
+ lscpu_info[:vulnerability][name] = description
166
+ when /^Flags:\s+(.+)/
167
+ lscpu_info[:flags] = $1.split(" ").sort
168
+ # flags are "features" on aarch64 and s390x so add it for backwards computability
169
+ lscpu_info[:features] = lscpu_info[:flags] if lscpu_info[:architecture].match?(/aarch64|s390x/)
170
+ end
171
+ end
172
+
173
+ case lscpu_info[:architecture]
174
+ when "s390x"
175
+ # Add data from /proc/cpuinfo that isn't available from lscpu
176
+ lscpu_info[:bogomips_per_cpu] = cpu_info[:bogomips_per_cpu]
177
+ lscpu_info[:version] = cpu_info["0"][:version]
178
+ lscpu_info[:identification] = cpu_info["0"][:identification]
179
+ lscpu_info[:machine] = cpu_info["0"][:machine]
180
+ lscpu_total = lscpu_info[:sockets_per_book] * lscpu_info[:cores_per_socket] * lscpu_info[:threads_per_core] * lscpu_info[:books_per_drawer] * lscpu_info[:drawers]
181
+ lscpu_real = lscpu_info[:sockets_per_book]
182
+ lscpu_cores = lscpu_info[:sockets_per_book] * lscpu_info[:cores_per_socket] * lscpu_info[:books_per_drawer] * lscpu_info[:drawers]
183
+ when "ppc64le"
184
+ # Add data from /proc/cpuinfo that isn't available from lscpu
185
+ lscpu_info[:timebase] = cpu_info[:timebase]
186
+ lscpu_info[:platform] = cpu_info[:platform]
187
+ lscpu_info[:machine_model] = cpu_info[:machine_model]
188
+ lscpu_info[:machine] = cpu_info[:machine]
189
+ lscpu_info[:firmware] = cpu_info[:firmware] if cpu_info[:firmware]
190
+ lscpu_info[:mmu] = cpu_info[:mmu] if cpu_info[:mmu]
191
+ lscpu_info[:mhz] = cpu_info["0"][:mhz]
192
+ lscpu_total = lscpu_info[:sockets] * lscpu_info[:cores_per_socket] * lscpu_info[:threads_per_core]
193
+ lscpu_real = lscpu_info[:sockets]
194
+ lscpu_cores = lscpu_info[:sockets] * lscpu_info[:cores_per_socket]
195
+ else
196
+ lscpu_total = lscpu_info[:sockets] * lscpu_info[:cores_per_socket] * lscpu_info[:threads_per_core]
197
+ lscpu_real = lscpu_info[:sockets]
198
+ lscpu_cores = lscpu_info[:sockets] * lscpu_info[:cores_per_socket]
199
+ end
200
+
201
+ # Enumerate cpus and fill out data to provide backwards compatibility data
202
+ cpu_cores.stdout.each_line do |line|
203
+ current_cpu = nil
204
+ current_core = nil
205
+ current_socket = nil
206
+
207
+ case line
208
+ # skip comments
209
+ when /^#/
210
+ next
211
+ # Parse data from "lscpu -p=CPU,CORE,SOCKET"
212
+ when /(\d+),(\d+),(\d+)/
213
+ current_cpu = $1
214
+ current_core = $2
215
+ current_socket = $3
216
+ end
217
+ lscpu_info[current_cpu] = Mash.new
218
+ lscpu_info[current_cpu][:vendor_id] = lscpu_info[:vendor_id] if lscpu_info[:vendor_id]
219
+ lscpu_info[current_cpu][:family] = lscpu_info[:family] if lscpu_info[:family]
220
+ lscpu_info[current_cpu][:model] = lscpu_info[:model] if lscpu_info[:model]
221
+ lscpu_info[current_cpu][:model_name] = lscpu_info[:model_name] if lscpu_info[:model_name]
222
+ lscpu_info[current_cpu][:stepping] = lscpu_info[:stepping] if lscpu_info[:stepping]
223
+ lscpu_info[current_cpu][:mhz] = lscpu_info[:mhz] if lscpu_info[:mhz]
224
+ lscpu_info[current_cpu][:bogomips] = lscpu_info[:bogomips] if lscpu_info[:bogomips]
225
+ # Per cpu cache_size is only really available from /proc/cpuinfo on x86
226
+ lscpu_info[current_cpu][:cache_size] = cpu_info[current_cpu][:cache_size] if cpu_info[current_cpu] && cpu_info[current_cpu][:cache_size]
227
+ lscpu_info[current_cpu][:physical_id] = current_socket
228
+ lscpu_info[current_cpu][:core_id] = current_core
229
+ lscpu_info[current_cpu][:cores] = lscpu_info[:cores_per_socket].to_s
230
+ lscpu_info[current_cpu][:flags] = lscpu_info[:flags] if lscpu_info[:flags]
231
+ lscpu_info[current_cpu][:features] = lscpu_info[:flags] if lscpu_info[:architecture].match?(/aarch64|s390x/)
232
+ if lscpu_info[:architecture] == "s390x"
233
+ lscpu_info[current_cpu][:version] = cpu_info[current_cpu][:version] if cpu_info[current_cpu][:version]
234
+ lscpu_info[current_cpu][:identification] = cpu_info[current_cpu][:identification] if cpu_info[current_cpu][:identification]
235
+ lscpu_info[current_cpu][:machine] = cpu_info[current_cpu][:machine] if cpu_info[current_cpu][:machine]
236
+ end
237
+ end
238
+ lscpu_info[:total] = lscpu_total
239
+ lscpu_info[:real] = lscpu_real
240
+ lscpu_info[:cores] = lscpu_cores
241
+ else
242
+ logger.trace("Plugin CPU: Error executing lscpu. CPU data may not be available.")
243
+ end
244
+ rescue Ohai::Exceptions::Exec # util-linux isn't installed most likely
245
+ logger.trace("Plugin CPU: Error executing lscpu. util-linux may not be installed.")
246
+ end
247
+ lscpu_info
248
+ end
249
+
250
+ def parse_cpuinfo
50
251
  cpuinfo = Mash.new
51
252
  real_cpu = Mash.new
52
253
  cpu_number = 0
53
254
  current_cpu = nil
54
255
 
55
- file_open("/proc/cpuinfo").each do |line|
256
+ file_open("/proc/cpuinfo").each_line do |line|
56
257
  case line
57
258
  when /processor\s+:\s(.+)/
58
259
  cpuinfo[$1] = Mash.new
@@ -68,7 +269,11 @@ Ohai.plugin(:CPU) do
68
269
  when /cpu family\s+:\s(.+)/
69
270
  cpuinfo[current_cpu]["family"] = $1
70
271
  when /model\s+:\s(.+)/
71
- cpuinfo[current_cpu]["model"] = $1
272
+ model = $1
273
+ cpuinfo[current_cpu]["model"] = model
274
+ # ppc has "model" at the end of /proc/cpuinfo. In addition it should always include a include a dash or "IBM".
275
+ # So let's put this in cpu/model on ppc
276
+ cpuinfo["machine_model"] = model if model.match?(/-|IBM/)
72
277
  when /stepping\s+:\s(.+)/
73
278
  cpuinfo[current_cpu]["stepping"] = $1
74
279
  when /physical id\s+:\s(.+)/
@@ -94,6 +299,24 @@ Ohai.plugin(:CPU) do
94
299
  cpuinfo["bogomips_per_cpu"] = $1
95
300
  when /features\s+:\s(.+)/
96
301
  cpuinfo["features"] = $1.split
302
+ # ppc64le
303
+ when /revision\s+:\s(.+)/
304
+ cpuinfo[current_cpu]["model"] = $1
305
+ when /cpu\s+:\s(.+)/
306
+ cpuinfo[current_cpu]["model_name"] = $1
307
+ when /clock\s+:\s(.+)/
308
+ cpuinfo[current_cpu]["mhz"] = $1
309
+ when /timebase\s+:\s(.+)/
310
+ cpuinfo["timebase"] = $1
311
+ when /platform\s+:\s(.+)/
312
+ cpuinfo["platform"] = $1
313
+ when /machine\s+:\s(.+)/
314
+ cpuinfo["machine"] = $1
315
+ when /firmware\s+:\s(.+)/
316
+ cpuinfo["firmware"] = $1
317
+ when /MMU\s+:\s(.+)/
318
+ cpuinfo["mmu"] = $1
319
+ # s390x
97
320
  when /processor\s(\d):\s(.+)/
98
321
  current_cpu = $1
99
322
  cpu_number += 1
@@ -108,40 +331,28 @@ Ohai.plugin(:CPU) do
108
331
  end
109
332
  end
110
333
 
111
- cpu cpuinfo
112
-
113
- cpu[:total] = cpu_number
114
-
115
334
  # use data we collected unless cpuinfo is lacking core information
116
335
  # which is the case on older linux distros
117
- if !real_cpu.empty? && cpu["0"]["cores"]
118
- cpu[:real] = real_cpu.keys.length
119
- cpu[:cores] = real_cpu.keys.length * cpu["0"]["cores"].to_i
336
+ if !real_cpu.empty? && cpuinfo["0"]["cores"]
337
+ logger.trace("Plugin CPU: Error executing lscpu. CPU data may not be available.")
338
+ cpuinfo[:real] = real_cpu.keys.length
339
+ cpuinfo[:cores] = real_cpu.keys.length * cpuinfo["0"]["cores"].to_i
120
340
  else
121
- begin
122
- logger.trace("Plugin CPU: Falling back to aggregate data from lscpu as real cpu & core data is missing in /proc/cpuinfo")
123
- so = shell_out("lscpu")
124
- if so.exitstatus == 0
125
- lscpu_data = Mash.new
126
- so.stdout.each_line do |line|
127
- case line
128
- when /^Thread\(s\) per core:\s(.+)/ # http://rubular.com/r/lOw2pRrw1q
129
- lscpu_data[:threads] = $1.to_i
130
- when /^Core\(s\) per socket:\s(.+)/ # http://rubular.com/r/lOw2pRrw1q
131
- lscpu_data[:cores] = $1.to_i
132
- when /^Socket\(s\):\s(.+)/ # http://rubular.com/r/DIzmPtJFvK
133
- lscpu_data[:sockets] = $1.to_i
134
- end
135
- end
136
- cpu[:total] = lscpu_data[:sockets] * lscpu_data[:cores] * lscpu_data[:threads]
137
- cpu[:real] = lscpu_data[:sockets]
138
- cpu[:cores] = lscpu_data[:sockets] * lscpu_data[:cores]
139
- else
140
- logger.trace("Plugin CPU: Error executing lscpu. CPU data may not be available.")
141
- end
142
- rescue Ohai::Exceptions::Exec # util-linux isn't installed most likely
143
- logger.trace("Plugin CPU: Error executing lscpu. util-linux may not be installed.")
144
- end
341
+ logger.trace("Plugin CPU: real cpu & core data is missing in /proc/cpuinfo and lscpu")
342
+ end
343
+ cpuinfo[:total] = cpu_number
344
+ cpuinfo
345
+ end
346
+
347
+ collect_data(:linux) do
348
+ cpuinfo = parse_cpuinfo
349
+ lscpu = parse_lscpu(cpuinfo)
350
+
351
+ # If we don't have any data from lscpu then get it from /proc/cpuinfo
352
+ if lscpu.empty?
353
+ cpu cpuinfo
354
+ else
355
+ cpu lscpu
145
356
  end
146
357
  end
147
358
 
@@ -98,14 +98,6 @@ Ohai.plugin(:Filesystem) do
98
98
  view
99
99
  end
100
100
 
101
- def generate_deprecated_windows_view(fs)
102
- view = generate_mountpoint_view(fs)
103
- view.each do |mp, entry|
104
- view[mp].delete("devices")
105
- end
106
- view
107
- end
108
-
109
101
  def parse_common_df(out)
110
102
  fs = {}
111
103
  out.each_line do |line|
@@ -466,9 +458,7 @@ Ohai.plugin(:Filesystem) do
466
458
  fs_data["by_mountpoint"] = by_mountpoint
467
459
  fs_data["by_pair"] = by_pair
468
460
 
469
- # @todo in Chef 17 the filesystem2 part of this goes away
470
461
  filesystem fs_data
471
- filesystem2 fs_data
472
462
  end
473
463
 
474
464
  collect_data(:darwin) do
@@ -613,9 +603,7 @@ Ohai.plugin(:Filesystem) do
613
603
  fs_data["by_mountpoint"] = by_mountpoint
614
604
  fs_data["by_pair"] = by_pair
615
605
 
616
- # @todo in Chef 17 the filesystem2 plugin goes away
617
606
  filesystem fs_data
618
- filesystem2 fs_data
619
607
  end
620
608
 
621
609
  collect_data(:aix) do
@@ -705,9 +693,7 @@ Ohai.plugin(:Filesystem) do
705
693
  fs_data["by_mountpoint"] = by_mountpoint
706
694
  fs_data["by_pair"] = by_pair
707
695
 
708
- # @todo in Chef 17 the filesystem2 plugin goes away here
709
696
  filesystem fs_data
710
- filesystem2 fs_data
711
697
  end
712
698
 
713
699
  collect_data(:windows) do
@@ -726,9 +712,10 @@ Ohai.plugin(:Filesystem) do
726
712
  fs_data["by_mountpoint"] = by_mountpoint
727
713
  fs_data["by_pair"] = by_pair
728
714
 
729
- # Set the filesystem data - Windows didn't do the conversion when everyone
730
- # else did, so 15 will have both be the new API and 16 will drop the old API
731
- filesystem generate_deprecated_windows_view(fs)
715
+ # Chef 16 added 'filesystem2'
716
+ # In Chef 17 we made 'filesystem' and 'filesystem2' match (both new-style)
717
+ # In Chef 18 we will drop 'filesystem2'
718
+ filesystem fs_data
732
719
  filesystem2 fs_data
733
720
  end
734
721
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ #
19
+ Ohai.plugin(:Habitat) do
20
+ provides "habitat"
21
+
22
+ def habitat_binary
23
+ @habitat_binary ||= which("hab")
24
+ end
25
+
26
+ def fetch_habitat_version
27
+ shell_out([habitat_binary, "-V"]).stdout.gsub(/hab\s*/, "").strip
28
+ rescue Ohai::Exceptions::Exec
29
+ logger.trace("Plugin Habitat: Unable to determine the installed version of Habitat, skipping collection.")
30
+ end
31
+
32
+ def fetch_habitat_packages
33
+ shell_out([habitat_binary, "pkg", "list", "--all"]).stdout.split.sort.select { |pkg| pkg.match?(%r{.*/.*/.*/.*}) }
34
+ rescue Ohai::Exceptions::Exec
35
+ logger.trace("Plugin Habitat: Unable to determine the installed Habitat packages, skipping collection.")
36
+ end
37
+
38
+ def load_habitat_service_via_cli(status_stdout)
39
+ # package type desired state elapsed (s) pid group
40
+ # core/httpd/2.4.35/20190307151146 standalone up up 158169 1410 httpd.default
41
+ @services = []
42
+ status_stdout.each_line do |line|
43
+ fields = line.split(/\s+/)
44
+ next unless fields[0].match?(%r{.*/.*/.*/.*}) # ignore header line
45
+
46
+ service = {}
47
+ service[:identity] = fields[0]
48
+ service[:topology] = fields[1]
49
+ service[:state_desired] = fields[2]
50
+ service[:state_actual] = fields[2]
51
+ (@services).push(service)
52
+ end
53
+ @services
54
+ end
55
+
56
+ def fetch_habitat_services
57
+ services_shell_out = shell_out([habitat_binary, "svc", "status"]).stdout
58
+ load_habitat_service_via_cli(services_shell_out) if services_shell_out
59
+ rescue Ohai::Exceptions::Exec
60
+ logger.trace("Plugin Habitat: Unable to determine the installed Habitat services, skipping collection.")
61
+ end
62
+
63
+ collect_data(:default) do
64
+ if habitat_binary
65
+ habitat Mash.new
66
+ habitat["version"] = fetch_habitat_version
67
+ habitat["packages"] = fetch_habitat_packages
68
+ habitat["services"] = fetch_habitat_services
69
+ else
70
+ logger.trace("Plugin Habitat: Could not find hab binary. Skipping plugin.")
71
+ end
72
+ end
73
+ end
@@ -48,7 +48,28 @@ Ohai.plugin(:Hostname) do
48
48
  require "ipaddr" unless defined?(IPAddr)
49
49
 
50
50
  hostname = from_cmd("hostname")
51
- addrinfo = Socket.getaddrinfo(hostname, nil).first
51
+ begin
52
+ addrinfo = Socket.getaddrinfo(hostname, nil).first
53
+ rescue SocketError
54
+ # In the event that we got an exception from Socket, it's possible
55
+ # that it will work if we restrict it to IPv4 only either because of
56
+ # IPv6 misconfiguration or other bugs.
57
+ #
58
+ # Specifically it's worth noting that on macOS, getaddrinfo() will choke
59
+ # if it gets back a link-local address (say if you have 'fe80::1 myhost'
60
+ # in /etc/hosts). This will raise:
61
+ # SocketError (getnameinfo: Non-recoverable failure in name resolution)
62
+ #
63
+ # But general misconfiguration could cause similar issues, so attempt to
64
+ # fall back to v4-only
65
+ begin
66
+ addrinfo = Socket.getaddrinfo(hostname, nil, :INET).first
67
+ rescue
68
+ # and if *that* fails, then try v6-only, in case we're in a v6-only
69
+ # environment with v4 config issues
70
+ addrinfo = Socket.getaddrinfo(hostname, nil, :INET6).first
71
+ end
72
+ end
52
73
  iaddr = IPAddr.new(addrinfo[3])
53
74
  Socket.gethostbyaddr(iaddr.hton)[0]
54
75
  rescue
@@ -80,22 +80,9 @@ Ohai.plugin(:Network) do
80
80
  line.strip!
81
81
  logger.trace("Plugin Network: Parsing #{line}")
82
82
  if /\\/.match?(line)
83
- # If we have multipath routing, then the first part will be a normal
84
- # looking route:
85
- # default proto ra metric 1024 <other options>
86
- # Each successive part after that is a hop without those options.
87
- # So the first thing we do is grab that first part, and split it into
88
- # the route destination ("default"), and the route options.
89
- parts = line.split("\\")
90
- route_dest, dest_opts = parts.first.split(nil, 2)
91
- # Then all the route endings, generally just nexthops.
92
- route_endings = parts[1..-1]
93
- if dest_opts && !dest_opts.empty?
94
- # Route options like proto, metric, etc. only appear once for each
95
- # multipath configuration. Prepend this information to the route
96
- # endings so the code below will assign the fields properly.
97
- route_endings.map! { |e| e.include?("nexthop") ? "#{dest_opts} #{e}" : e }
98
- end
83
+ parts = line.split('\\')
84
+ route_dest = parts.shift.strip
85
+ route_endings = parts
99
86
  elsif line =~ /^([^\s]+)\s(.*)$/
100
87
  route_dest = $1
101
88
  route_endings = [$2]
@@ -103,24 +90,9 @@ Ohai.plugin(:Network) do
103
90
  next
104
91
  end
105
92
  route_endings.each do |route_ending|
106
- route_entry = Mash.new(destination: route_dest,
107
- family: family[:name])
108
- route_int = nil
109
93
  if route_ending =~ /\bdev\s+([^\s]+)\b/
110
94
  route_int = $1
111
- end
112
- # does any known interface own the src address?
113
- # we try to infer the interface/device from its address if it isn't specified
114
- # we want to override the interface set via nexthop but only if possible
115
- if line =~ /\bsrc\s+([^\s]+)\b/ && (!route_int || line.include?("nexthop"))
116
- # only clobber previously set route_int if we find a match
117
- if (match = iface.select { |name, intf| intf.fetch("addresses", {}).any? { |addr, _| addr == $1 } }.keys.first)
118
- route_int = match
119
- route_entry[:inferred] = true
120
- end
121
- end
122
-
123
- unless route_int
95
+ else
124
96
  logger.trace("Plugin Network: Skipping route entry without a device: '#{line}'")
125
97
  next
126
98
  end
@@ -131,6 +103,8 @@ Ohai.plugin(:Network) do
131
103
  next
132
104
  end
133
105
 
106
+ route_entry = Mash.new(destination: route_dest,
107
+ family: family[:name])
134
108
  %w{via scope metric proto src}.each do |k|
135
109
  # http://rubular.com/r/pwTNp65VFf
136
110
  route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)/
@@ -167,13 +141,13 @@ Ohai.plugin(:Network) do
167
141
 
168
142
  # using a temporary var to hold routes and their interface name
169
143
  def parse_routes(family, iface)
170
- iface.collect do |i, iv|
144
+ iface.filter_map do |i, iv|
171
145
  next unless iv[:routes]
172
146
 
173
- iv[:routes].collect do |r|
147
+ iv[:routes].filter_map do |r|
174
148
  r.merge(dev: i) if r[:family] == family[:name]
175
- end.compact # @todo: when we drop ruby 2.6 this should be a filter_map
176
- end.compact.flatten # @todo: when we drop ruby 2.6 this should be a filter_map
149
+ end
150
+ end.flatten
177
151
  end
178
152
 
179
153
  # determine layer 1 details for the interface using ethtool
@@ -376,7 +350,6 @@ Ohai.plugin(:Network) do
376
350
  so = shell_out("ip -d -s link")
377
351
  tmp_int = nil
378
352
  on_rx = true
379
- xdp_mode = nil
380
353
  so.stdout.lines do |line|
381
354
  if line =~ IPROUTE_INT_REGEX
382
355
  tmp_int = $2
@@ -452,30 +425,6 @@ Ohai.plugin(:Network) do
452
425
  if line =~ /\sstate (\w+)/
453
426
  iface[tmp_int]["state"] = $1.downcase
454
427
  end
455
-
456
- if line.include?("xdp")
457
- mode = line.scan(/\s(xdp|xdpgeneric|xdpoffload|xdpmulti)\s/).flatten[0]
458
- # Fetches and sets the mode from the first line.
459
- unless mode.nil?
460
- iface[tmp_int][:xdp] = {}
461
- if mode.eql?("xdp")
462
- # In case of xdpdrv, mode is xdp,
463
- # to keep it consistent, keeping mode as xdpdrv.
464
- mode = "xdpdrv"
465
- end
466
- xdp_mode = mode
467
- iface[tmp_int][:xdp][:attached] = []
468
- end
469
-
470
- if line =~ %r{prog/(\w+) id (\d+) tag (\w+)}
471
- mode = $1.eql?("xdp") ? xdp_mode : $1
472
- iface[tmp_int][:xdp][:attached] << {
473
- mode: mode,
474
- id: $2,
475
- tag: $3,
476
- }
477
- end
478
- end
479
428
  end
480
429
  iface
481
430
  end
@@ -658,12 +607,10 @@ Ohai.plugin(:Network) do
658
607
  # sorting the selected routes:
659
608
  # - getting default routes first
660
609
  # - then sort by metric
661
- # - then sort by if the device was inferred or not (preferring explicit to inferred)
662
610
  # - then by prefixlen
663
611
  [
664
612
  r[:destination] == "default" ? 0 : 1,
665
613
  r[:metric].nil? ? 0 : r[:metric].to_i,
666
- r[:inferred] ? 1 : 0,
667
614
  # for some reason IPAddress doesn't accept "::/0", it doesn't like prefix==0
668
615
  # just a quick workaround: use 0 if IPAddress fails
669
616
  begin
@@ -876,4 +823,4 @@ Ohai.plugin(:Network) do
876
823
  counters[:network][:interfaces] = net_counters
877
824
  network["interfaces"] = iface
878
825
  end
879
- end
826
+ end
@@ -137,7 +137,7 @@ Ohai.plugin(:Platform) do
137
137
  when /ubuntu/, /debian/, /linuxmint/, /raspbian/, /cumulus/, /kali/, /pop/
138
138
  # apt-get+dpkg almost certainly goes here
139
139
  "debian"
140
- when /centos/, /redhat/, /oracle/, /almalinux/, /rocky/, /scientific/, /enterpriseenterprise/, /xenserver/, /xcp-ng/, /cloudlinux/, /alibabalinux/, /sangoma/, /clearos/, /parallels/, /ibm_powerkvm/, /nexus_centos/, /bigip/, /virtuozzo/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
140
+ when /centos/, /redhat/, /oracle/, /almalinux/, /scientific/, /enterpriseenterprise/, /xenserver/, /xcp-ng/, /cloudlinux/, /alibabalinux/, /sangoma/, /clearos/, /parallels/, /ibm_powerkvm/, /nexus_centos/, /bigip/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
141
141
  # NOTE: "rhel" should be reserved exclusively for recompiled rhel versions that are nearly perfectly compatible down to the platform_version.
142
142
  # The operating systems that are "rhel" should all be as compatible as rhel7 = centos7 = oracle7 = scientific7 (98%-ish core RPM version compatibility
143
143
  # and the version numbers MUST track the upstream). The appropriate EPEL version repo should work nearly perfectly. Some variation like the
@@ -151,7 +151,7 @@ Ohai.plugin(:Platform) do
151
151
  "amazon"
152
152
  when /suse/, /sles/, /opensuseleap/, /opensuse/, /sled/
153
153
  "suse"
154
- when /fedora/, /pidora/, /arista_eos/
154
+ when /fedora/, /arista_eos/
155
155
  # In the broadest sense: RPM-based, fedora-derived distributions which are not strictly re-compiled RHEL (if it uses RPMs, and smells more like redhat and less like
156
156
  # SuSE it probably goes here).
157
157
  "fedora"
@@ -159,7 +159,7 @@ Ohai.plugin(:Platform) do
159
159
  "wrlinux"
160
160
  when /gentoo/
161
161
  "gentoo"
162
- when /arch/, /manjaro/, /antergos/
162
+ when /arch/, /manjaro/
163
163
  "arch"
164
164
  when /exherbo/
165
165
  "exherbo"
@@ -20,6 +20,7 @@
20
20
  Ohai.plugin(:Virtualization) do
21
21
  provides "virtualization"
22
22
  depends "dmi"
23
+ depends "cpu"
23
24
  require_relative "../../mixin/dmi_decode"
24
25
  include Ohai::Mixin::DmiDecode
25
26
 
@@ -35,6 +36,10 @@ Ohai.plugin(:Virtualization) do
35
36
  which("docker")
36
37
  end
37
38
 
39
+ def podman_exists?
40
+ which("podman")
41
+ end
42
+
38
43
  collect_data(:linux) do
39
44
  virtualization Mash.new unless virtualization
40
45
  virtualization[:systems] ||= Mash.new
@@ -46,6 +51,13 @@ Ohai.plugin(:Virtualization) do
46
51
  virtualization[:systems][:docker] = "host"
47
52
  end
48
53
 
54
+ # Podman hosts
55
+ if podman_exists?
56
+ virtualization[:system] = "podman"
57
+ virtualization[:role] = "host"
58
+ virtualization[:systems][:podman] = "host"
59
+ end
60
+
49
61
  # Xen Notes:
50
62
  # - /proc/xen is an empty dir for EL6 + Linode Guests + Paravirt EC2 instances
51
63
  # - cpuid of guests, if we could get it, would also be a clue
@@ -115,6 +127,14 @@ Ohai.plugin(:Virtualization) do
115
127
  virtualization[:role] = "host"
116
128
  virtualization[:systems][:kvm] = "host"
117
129
  end
130
+ elsif get_attribute(:cpu, :hypervisor_vendor)
131
+ if get_attribute(:cpu, :hypervisor_vendor) == "KVM"
132
+ virtualization[:system] = "kvm"
133
+ if /(para|full)/.match?(get_attribute(:cpu, :virtualization_type))
134
+ virtualization[:role] = "guest"
135
+ virtualization[:systems][:kvm] = "guest"
136
+ end
137
+ end
118
138
  end
119
139
 
120
140
  # parse dmi to discover various virtualization guests
@@ -188,7 +208,7 @@ Ohai.plugin(:Virtualization) do
188
208
  # <index #>:<subsystem>:/
189
209
  #
190
210
  # Full notes, https://tickets.opscode.com/browse/OHAI-551
191
- # Kernel docs, https://www.kernel.org/doc/Documentation/cgroups
211
+ # Kernel docs, https://web.archive.org/web/20100514070914/http://www.kernel.org/doc/Documentation/cgroups/
192
212
  if file_exist?("/proc/self/cgroup")
193
213
  cgroup_content = file_read("/proc/self/cgroup")
194
214
  # These two REs catch many different examples. Here's a specific one
@@ -210,6 +230,20 @@ Ohai.plugin(:Virtualization) do
210
230
  virtualization[:system] = "nspawn"
211
231
  virtualization[:role] = "guest"
212
232
  virtualization[:systems][:nspawn] = "guest"
233
+ elsif /container=podman/.match?(file_read("/proc/1/environ"))
234
+ logger.trace("Plugin Virtualization: /proc/1/environ indicates podman container. Detecting as podman guest")
235
+ virtualization[:system] = "podman"
236
+ virtualization[:role] = "guest"
237
+ virtualization[:systems][:podman] = "guest"
238
+ # Detect any containers that appear to be using docker such as those running on Github Actions virtual machines
239
+ # but aren't triggered by the cgroup regex above. It's pretty safe to assume if the cgroup contains containerd,
240
+ # it's likely using docker.
241
+ # https://rubular.com/r/qhSmV113cPmEBT
242
+ elsif %r{^\d+:[^:]*:/[^/]+/(containerd)-?.+$}.match?(cgroup_content)
243
+ logger.trace("Plugin Virtualization: /proc/self/cgroup indicates docker container. Detecting as docker guest")
244
+ virtualization[:system] = "docker"
245
+ virtualization[:role] = "guest"
246
+ virtualization[:systems][:docker] = "guest"
213
247
  elsif lxc_version_exists? && file_read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$}
214
248
  # lxc-version shouldn't be installed by default
215
249
  # Even so, it is likely we are on an LXC capable host that is not being used as such
@@ -82,7 +82,7 @@ Ohai.plugin(:NetworkAddresses) do
82
82
  elsif network[gw_attr] &&
83
83
  network["interfaces"][network[int_attr]] &&
84
84
  network["interfaces"][network[int_attr]]["addresses"]
85
- if [ "0.0.0.0", "::", /^fe80:/ ].any? { |pat| pat === network[gw_attr] }
85
+ if [ "0.0.0.0", "::", /^fe80:/ ].any? { |pat| pat === network[gw_attr] } # rubocop: disable Performance/RedundantEqualityComparisonBlock
86
86
  # link level default route
87
87
  logger.trace("Plugin Network: link level default #{family} route, picking ip from #{network[gw_attr]}")
88
88
  r = gw_if_ips.first
@@ -134,9 +134,8 @@ Ohai.plugin(:Packages) do
134
134
  require "win32/registry" unless defined?(Win32::Registry)
135
135
  packages Mash.new
136
136
  collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
137
- # on 64 bit systems, 32 bit programs are stored here moved before HKEY_CURRENT_USER otherwise it is not collected (impacts both ohai 16 & 17)
137
+ collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
138
138
  collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
139
- collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall') rescue nil
140
139
  # on 64 bit systems, 32 bit programs are stored here
141
140
  end
142
141
 
data/lib/ohai/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
 
20
20
  module Ohai
21
21
  OHAI_ROOT = File.expand_path(__dir__)
22
- VERSION = "16.17.2"
22
+ VERSION = "17.0.42"
23
23
  end
data/ohai.gemspec CHANGED
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.email = "adam@chef.io"
13
13
  s.homepage = "https://github.com/chef/ohai/"
14
14
 
15
- s.required_ruby_version = ">= 2.6"
15
+ s.required_ruby_version = ">= 2.7"
16
16
 
17
- s.add_dependency "chef-config", ">= 14.12", "< 17"
18
- s.add_dependency "chef-utils", ">= 16.0", "< 17"
17
+ s.add_dependency "chef-config", ">= 14.12", "< 18"
18
+ s.add_dependency "chef-utils", ">= 16.0", "< 18"
19
19
  s.add_dependency "ffi", "~> 1.9"
20
20
  s.add_dependency "ffi-yajl", "~> 2.2"
21
21
  s.add_dependency "ipaddress"
@@ -26,10 +26,6 @@ Gem::Specification.new do |s|
26
26
  s.add_dependency "plist", "~> 3.1"
27
27
  s.add_dependency "train-core"
28
28
  s.add_dependency "wmi-lite", "~> 1.0"
29
- # Note for ohai developers: If chef-config causes you grief, try:
30
- # bundle install --with development
31
- # this should work as long as chef is a development dependency in Gemfile.
32
- #
33
29
 
34
30
  s.bindir = "bin"
35
31
  s.executables = %w{ohai}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.17.2
4
+ version: 17.0.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-31 00:00:00.000000000 Z
11
+ date: 2021-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '14.12'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '17'
22
+ version: '18'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '14.12'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '17'
32
+ version: '18'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: chef-utils
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '16.0'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '17'
42
+ version: '18'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '16.0'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '17'
52
+ version: '18'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: ffi
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -230,6 +230,7 @@ files:
230
230
  - lib/ohai/loader.rb
231
231
  - lib/ohai/log.rb
232
232
  - lib/ohai/mash.rb
233
+ - lib/ohai/mixin/alibaba_metadata.rb
233
234
  - lib/ohai/mixin/azure_metadata.rb
234
235
  - lib/ohai/mixin/chef_utils_wiring.rb
235
236
  - lib/ohai/mixin/command.rb
@@ -255,6 +256,7 @@ files:
255
256
  - lib/ohai/plugins/aix/platform.rb
256
257
  - lib/ohai/plugins/aix/uptime.rb
257
258
  - lib/ohai/plugins/aix/virtualization.rb
259
+ - lib/ohai/plugins/alibaba.rb
258
260
  - lib/ohai/plugins/azure.rb
259
261
  - lib/ohai/plugins/bsd/virtualization.rb
260
262
  - lib/ohai/plugins/c.rb
@@ -286,6 +288,7 @@ files:
286
288
  - lib/ohai/plugins/go.rb
287
289
  - lib/ohai/plugins/groovy.rb
288
290
  - lib/ohai/plugins/grub2.rb
291
+ - lib/ohai/plugins/habitat.rb
289
292
  - lib/ohai/plugins/haskell.rb
290
293
  - lib/ohai/plugins/hostname.rb
291
294
  - lib/ohai/plugins/init_package.rb
@@ -385,7 +388,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
385
388
  requirements:
386
389
  - - ">="
387
390
  - !ruby/object:Gem::Version
388
- version: '2.6'
391
+ version: '2.7'
389
392
  required_rubygems_version: !ruby/object:Gem::Requirement
390
393
  requirements:
391
394
  - - ">="