ohai 16.4.11 → 16.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +11 -6
- data/bin/ohai +1 -1
- data/lib/ohai.rb +1 -1
- data/lib/ohai/application.rb +39 -0
- data/lib/ohai/common/dmi.rb +7 -3
- data/lib/ohai/config.rb +2 -3
- data/lib/ohai/dsl.rb +1 -1
- data/lib/ohai/dsl/plugin.rb +12 -5
- data/lib/ohai/dsl/plugin/versionvii.rb +28 -16
- data/lib/ohai/exception.rb +1 -1
- data/lib/ohai/hints.rb +1 -1
- data/lib/ohai/loader.rb +1 -1
- data/lib/ohai/log.rb +1 -1
- data/lib/ohai/mixin/azure_metadata.rb +1 -1
- data/lib/ohai/mixin/chef_utils_wiring.rb +51 -0
- data/lib/ohai/mixin/command.rb +3 -54
- data/lib/ohai/mixin/constant_helper.rb +1 -1
- data/lib/ohai/mixin/dmi_decode.rb +1 -1
- data/lib/ohai/mixin/do_metadata.rb +1 -1
- data/lib/ohai/mixin/ec2_metadata.rb +3 -3
- data/lib/ohai/mixin/http_helper.rb +1 -1
- data/lib/ohai/mixin/network_helper.rb +1 -1
- data/lib/ohai/mixin/os.rb +67 -2
- data/lib/ohai/mixin/scaleway_metadata.rb +1 -1
- data/lib/ohai/mixin/seconds_to_human.rb +1 -1
- data/lib/ohai/mixin/shell_out.rb +50 -0
- data/lib/ohai/mixin/string.rb +1 -1
- data/lib/ohai/mixin/train_helpers.rb +35 -0
- data/lib/ohai/mixin/which.rb +38 -0
- data/lib/ohai/plugin_config.rb +1 -1
- data/lib/ohai/plugins/aix/kernel.rb +1 -1
- data/lib/ohai/plugins/aix/memory.rb +3 -3
- data/lib/ohai/plugins/aix/network.rb +1 -1
- data/lib/ohai/plugins/aix/platform.rb +1 -1
- data/lib/ohai/plugins/aix/uptime.rb +1 -1
- data/lib/ohai/plugins/aix/virtualization.rb +1 -1
- data/lib/ohai/plugins/azure.rb +25 -5
- data/lib/ohai/plugins/bsd/virtualization.rb +3 -3
- data/lib/ohai/plugins/chef.rb +1 -1
- data/lib/ohai/plugins/cloud.rb +1 -1
- data/lib/ohai/plugins/command.rb +1 -1
- data/lib/ohai/plugins/cpu.rb +6 -6
- data/lib/ohai/plugins/darwin/memory.rb +1 -1
- data/lib/ohai/plugins/darwin/network.rb +1 -1
- data/lib/ohai/plugins/darwin/platform.rb +2 -2
- data/lib/ohai/plugins/darwin/virtualization.rb +2 -2
- data/lib/ohai/plugins/dmi.rb +1 -1
- data/lib/ohai/plugins/docker.rb +1 -1
- data/lib/ohai/plugins/ec2.rb +15 -9
- data/lib/ohai/plugins/erlang.rb +1 -1
- data/lib/ohai/plugins/eucalyptus.rb +1 -1
- data/lib/ohai/plugins/filesystem.rb +4 -4
- data/lib/ohai/plugins/fips.rb +1 -1
- data/lib/ohai/plugins/gce.rb +2 -2
- data/lib/ohai/plugins/hostname.rb +1 -1
- data/lib/ohai/plugins/init_package.rb +2 -2
- data/lib/ohai/plugins/java.rb +1 -1
- data/lib/ohai/plugins/joyent.rb +2 -2
- data/lib/ohai/plugins/kernel.rb +9 -5
- data/lib/ohai/plugins/keys.rb +1 -1
- data/lib/ohai/plugins/languages.rb +1 -1
- data/lib/ohai/plugins/libvirt.rb +1 -1
- data/lib/ohai/plugins/linode.rb +1 -1
- data/lib/ohai/plugins/linux/block_device.rb +9 -9
- data/lib/ohai/plugins/linux/interrupts.rb +3 -3
- data/lib/ohai/plugins/linux/ipc.rb +1 -1
- data/lib/ohai/plugins/linux/lsb.rb +4 -4
- data/lib/ohai/plugins/linux/machineid.rb +4 -4
- data/lib/ohai/plugins/linux/mdadm.rb +2 -2
- data/lib/ohai/plugins/linux/memory.rb +2 -2
- data/lib/ohai/plugins/linux/network.rb +13 -13
- data/lib/ohai/plugins/linux/platform.rb +30 -30
- data/lib/ohai/plugins/linux/virtualization.rb +24 -24
- data/lib/ohai/plugins/network.rb +1 -1
- data/lib/ohai/plugins/ohai_time.rb +2 -2
- data/lib/ohai/plugins/openstack.rb +1 -1
- data/lib/ohai/plugins/os.rb +5 -1
- data/lib/ohai/plugins/packages.rb +20 -0
- data/lib/ohai/plugins/passwd.rb +57 -1
- data/lib/ohai/plugins/perl.rb +1 -1
- data/lib/ohai/plugins/platform.rb +1 -1
- data/lib/ohai/plugins/powershell.rb +1 -1
- data/lib/ohai/plugins/ps.rb +1 -1
- data/lib/ohai/plugins/python.rb +1 -1
- data/lib/ohai/plugins/rackspace.rb +2 -2
- data/lib/ohai/plugins/scaleway.rb +1 -1
- data/lib/ohai/plugins/shard.rb +1 -1
- data/lib/ohai/plugins/shells.rb +3 -3
- data/lib/ohai/plugins/softlayer.rb +1 -1
- data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
- data/lib/ohai/plugins/solaris2/network.rb +6 -8
- data/lib/ohai/plugins/solaris2/platform.rb +3 -3
- data/lib/ohai/plugins/solaris2/virtualization.rb +2 -2
- data/lib/ohai/plugins/ssh_host_key.rb +13 -13
- data/lib/ohai/plugins/train.rb +35 -0
- data/lib/ohai/plugins/uptime.rb +2 -2
- data/lib/ohai/plugins/virtualbox.rb +1 -1
- data/lib/ohai/plugins/vmware.rb +2 -2
- data/lib/ohai/plugins/windows/drivers.rb +1 -1
- data/lib/ohai/plugins/windows/network.rb +2 -2
- data/lib/ohai/plugins/windows/platform.rb +1 -1
- data/lib/ohai/plugins/windows/system_enclosure.rb +1 -1
- data/lib/ohai/plugins/windows/virtualization.rb +1 -1
- data/lib/ohai/plugins/zpools.rb +1 -1
- data/lib/ohai/provides_map.rb +1 -1
- data/lib/ohai/runner.rb +5 -1
- data/lib/ohai/system.rb +34 -7
- data/lib/ohai/train_transport.rb +28 -0
- data/lib/ohai/util/file_helper.rb +4 -37
- data/lib/ohai/util/win32.rb +1 -1
- data/lib/ohai/version.rb +3 -3
- data/ohai.gemspec +7 -7
- metadata +80 -60
@@ -25,7 +25,7 @@ Ohai.plugin(:Interrupts) do
|
|
25
25
|
# format: comma-separate list of 32bit bitmask in hex
|
26
26
|
# each bit is a CPU, right to left ordering (i.e. CPU0 is rightmost)
|
27
27
|
def parse_smp_affinity(path, cpus)
|
28
|
-
masks =
|
28
|
+
masks = file_read(path).strip
|
29
29
|
bit_masks = []
|
30
30
|
masks.split(",").each do |mask|
|
31
31
|
bit_masks << mask.rjust(8, "0").to_i(16).to_s(2)
|
@@ -47,7 +47,7 @@ Ohai.plugin(:Interrupts) do
|
|
47
47
|
parse_smp_affinity("/proc/irq/default_smp_affinity", cpus)
|
48
48
|
|
49
49
|
interrupts[:irq] = Mash.new
|
50
|
-
|
50
|
+
file_open("/proc/interrupts").each do |line|
|
51
51
|
# Documentation: https://www.kernel.org/doc/Documentation/filesystems/proc.txt
|
52
52
|
# format is "{irqn}: {CPUn...} [type] [vector] [device]"
|
53
53
|
irqn, fields = line.split(":", 2)
|
@@ -70,7 +70,7 @@ Ohai.plugin(:Interrupts) do
|
|
70
70
|
interrupts[:irq][irqn][:vector],
|
71
71
|
interrupts[:irq][irqn][:device] =
|
72
72
|
fields[cpus].split
|
73
|
-
if
|
73
|
+
if file_exist?("/proc/irq/#{irqn}/smp_affinity")
|
74
74
|
interrupts[:irq][irqn][:smp_affinity_by_cpu] =
|
75
75
|
parse_smp_affinity("/proc/irq/#{irqn}/smp_affinity", cpus)
|
76
76
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -22,7 +22,7 @@ Ohai.plugin(:LSB) do
|
|
22
22
|
collect_data(:linux) do
|
23
23
|
lsb Mash.new
|
24
24
|
|
25
|
-
if
|
25
|
+
if file_exist?("/usr/bin/lsb_release")
|
26
26
|
# From package redhat-lsb on Fedora/Redhat, lsb-release on Debian/Ubuntu
|
27
27
|
shell_out("lsb_release -a").stdout.lines do |line|
|
28
28
|
case line
|
@@ -38,9 +38,9 @@ Ohai.plugin(:LSB) do
|
|
38
38
|
lsb[:id] = line
|
39
39
|
end
|
40
40
|
end
|
41
|
-
elsif
|
41
|
+
elsif file_exist?("/etc/lsb-release")
|
42
42
|
# Old, non-standard Debian support
|
43
|
-
|
43
|
+
file_open("/etc/lsb-release").each do |line|
|
44
44
|
case line
|
45
45
|
when /^DISTRIB_ID=["']?(.+?)["']?$/
|
46
46
|
lsb[:id] = $1
|
@@ -20,10 +20,10 @@ Ohai.plugin(:Machineid) do
|
|
20
20
|
provides "machine_id"
|
21
21
|
|
22
22
|
collect_data(:linux) do
|
23
|
-
if
|
24
|
-
mid =
|
25
|
-
elsif
|
26
|
-
mid =
|
23
|
+
if file_exist?("/etc/machine-id")
|
24
|
+
mid = file_read("/etc/machine-id").chomp
|
25
|
+
elsif file_exist?("/var/lib/dbus/machine-id")
|
26
|
+
mid = file_read("/var/lib/dbus/machine-id").chomp
|
27
27
|
else
|
28
28
|
mid = nil
|
29
29
|
end
|
@@ -53,9 +53,9 @@ Ohai.plugin(:Mdadm) do
|
|
53
53
|
|
54
54
|
collect_data(:linux) do
|
55
55
|
# gather a list of all raid arrays
|
56
|
-
if
|
56
|
+
if file_exist?("/proc/mdstat")
|
57
57
|
devices = {}
|
58
|
-
|
58
|
+
file_open("/proc/mdstat").each do |line|
|
59
59
|
if line =~ /(md[0-9]+)/
|
60
60
|
device = Regexp.last_match[1]
|
61
61
|
pieces = line.split(/\s+/)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -25,7 +25,7 @@ Ohai.plugin(:Memory) do
|
|
25
25
|
memory[:hugepages] = Mash.new
|
26
26
|
memory[:directmap] = Mash.new
|
27
27
|
|
28
|
-
|
28
|
+
file_open("/proc/meminfo").each do |line|
|
29
29
|
case line
|
30
30
|
when /^MemTotal:\s+(\d+) (.+)$/
|
31
31
|
memory[:total] = "#{$1}#{$2}"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
3
|
# Author:: Chris Read <chris.read@gmail.com>
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -35,7 +35,7 @@ Ohai.plugin(:Network) do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def ipv6_enabled?
|
38
|
-
|
38
|
+
file_exist? "/proc/net/if_inet6"
|
39
39
|
end
|
40
40
|
|
41
41
|
def ethtool_binary_path
|
@@ -43,11 +43,11 @@ Ohai.plugin(:Network) do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def is_openvz?
|
46
|
-
@openvz ||=
|
46
|
+
@openvz ||= file_directory?("/proc/vz")
|
47
47
|
end
|
48
48
|
|
49
49
|
def is_openvz_host?
|
50
|
-
is_openvz? &&
|
50
|
+
is_openvz? && file_directory?("/proc/bc")
|
51
51
|
end
|
52
52
|
|
53
53
|
def extract_neighbors(family, iface, neigh_attr)
|
@@ -141,12 +141,12 @@ Ohai.plugin(:Network) do
|
|
141
141
|
# using a temporary var to hold routes and their interface name
|
142
142
|
def parse_routes(family, iface)
|
143
143
|
iface.collect do |i, iv|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
end
|
149
|
-
end.compact.flatten
|
144
|
+
next unless iv[:routes]
|
145
|
+
|
146
|
+
iv[:routes].collect do |r|
|
147
|
+
r.merge(dev: i) if r[:family] == family[:name]
|
148
|
+
end.compact # @todo: when we drop ruby 2.6 this should be a filter_map
|
149
|
+
end.compact.flatten # @todo: when we drop ruby 2.6 this should be a filter_map
|
150
150
|
end
|
151
151
|
|
152
152
|
# determine layer 1 details for the interface using ethtool
|
@@ -264,7 +264,7 @@ Ohai.plugin(:Network) do
|
|
264
264
|
end
|
265
265
|
key, val = line.split(/:\s+/)
|
266
266
|
if val
|
267
|
-
coalesce_key =
|
267
|
+
coalesce_key = key.downcase.tr(" ", "_").to_s
|
268
268
|
iface[tmp_int]["coalesce_params"][coalesce_key] = val.to_i
|
269
269
|
end
|
270
270
|
end
|
@@ -289,7 +289,7 @@ Ohai.plugin(:Network) do
|
|
289
289
|
if val.nil?
|
290
290
|
val = ""
|
291
291
|
end
|
292
|
-
driver_key =
|
292
|
+
driver_key = key.downcase.tr(" ", "_").to_s
|
293
293
|
iface[tmp_int]["driver_info"][driver_key] = val.chomp
|
294
294
|
end
|
295
295
|
end
|
@@ -646,7 +646,7 @@ Ohai.plugin(:Network) do
|
|
646
646
|
logger.trace("Plugin Network: #{default_prefix}_interface set to #{default_route[:dev]}")
|
647
647
|
|
648
648
|
# setting gateway to 0.0.0.0 or :: if the default route is a link level one
|
649
|
-
network["#{default_prefix}_gateway"] = default_route[:via]
|
649
|
+
network["#{default_prefix}_gateway"] = default_route[:via] || family[:default_route].chomp("/0")
|
650
650
|
logger.trace("Plugin Network: #{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}")
|
651
651
|
|
652
652
|
# deduce the default route the user most likely cares about to pick {ip,mac,ip6}address below
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -43,9 +43,9 @@ Ohai.plugin(:Platform) do
|
|
43
43
|
# @returns [Hash] the file parsed into a Hash or nil
|
44
44
|
#
|
45
45
|
def read_os_release_info(file)
|
46
|
-
return nil unless
|
46
|
+
return nil unless file_exist?(file)
|
47
47
|
|
48
|
-
|
48
|
+
file_read(file).split.inject({}) do |map, line|
|
49
49
|
key, value = line.split("=")
|
50
50
|
map[key] = value.gsub(/\A"|"\Z/, "") if value
|
51
51
|
map
|
@@ -64,7 +64,7 @@ Ohai.plugin(:Platform) do
|
|
64
64
|
begin
|
65
65
|
os_release_info = read_os_release_info("/etc/os-release")
|
66
66
|
cisco_release_info = os_release_info["CISCO_RELEASE_INFO"] if os_release_info
|
67
|
-
if cisco_release_info &&
|
67
|
+
if cisco_release_info && file_exist?(cisco_release_info)
|
68
68
|
os_release_info.merge!(read_os_release_info(cisco_release_info))
|
69
69
|
end
|
70
70
|
os_release_info
|
@@ -77,7 +77,7 @@ Ohai.plugin(:Platform) do
|
|
77
77
|
# @returns [Boolean] if we are Cisco according to /etc/os-release
|
78
78
|
#
|
79
79
|
def os_release_file_is_cisco?
|
80
|
-
|
80
|
+
file_exist?("/etc/os-release") && os_release_info["CISCO_RELEASE_INFO"]
|
81
81
|
end
|
82
82
|
|
83
83
|
#
|
@@ -88,7 +88,7 @@ Ohai.plugin(:Platform) do
|
|
88
88
|
# @returns [String] bigip Linux version from /etc/f5-release
|
89
89
|
#
|
90
90
|
def bigip_version
|
91
|
-
release_contents =
|
91
|
+
release_contents = file_read("/etc/f5-release")
|
92
92
|
release_contents.match(/BIG-IP release (\S*)/)[1] # http://rubular.com/r/O8nlrBVqSb
|
93
93
|
rescue NoMethodError, Errno::ENOENT, Errno::EACCES # rescue regex failure, file missing, or permission denied
|
94
94
|
logger.warn("Detected F5 Big-IP, but /etc/f5-release could not be parsed to determine platform_version")
|
@@ -178,18 +178,18 @@ Ohai.plugin(:Platform) do
|
|
178
178
|
# @deprecated
|
179
179
|
def legacy_platform_detection
|
180
180
|
# platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching
|
181
|
-
if
|
182
|
-
contents =
|
181
|
+
if file_exist?("/etc/oracle-release")
|
182
|
+
contents = file_read("/etc/oracle-release").chomp
|
183
183
|
platform "oracle"
|
184
184
|
platform_version get_redhatish_version(contents)
|
185
|
-
elsif
|
186
|
-
contents =
|
185
|
+
elsif file_exist?("/etc/enterprise-release")
|
186
|
+
contents = file_read("/etc/enterprise-release").chomp
|
187
187
|
platform "oracle"
|
188
188
|
platform_version get_redhatish_version(contents)
|
189
|
-
elsif
|
189
|
+
elsif file_exist?("/etc/f5-release")
|
190
190
|
platform "bigip"
|
191
191
|
platform_version bigip_version
|
192
|
-
elsif
|
192
|
+
elsif file_exist?("/etc/debian_version")
|
193
193
|
# Ubuntu and Debian both have /etc/debian_version
|
194
194
|
# Ubuntu should always have a working lsb, debian does not by default
|
195
195
|
if /Ubuntu/i.match?(lsb[:id])
|
@@ -197,25 +197,25 @@ Ohai.plugin(:Platform) do
|
|
197
197
|
platform_version lsb[:release]
|
198
198
|
else
|
199
199
|
platform "debian"
|
200
|
-
platform_version
|
200
|
+
platform_version file_read("/etc/debian_version").chomp
|
201
201
|
end
|
202
|
-
elsif
|
203
|
-
contents =
|
202
|
+
elsif file_exist?("/etc/parallels-release")
|
203
|
+
contents = file_read("/etc/parallels-release").chomp
|
204
204
|
platform get_redhatish_platform(contents)
|
205
205
|
platform_version contents.match(/(\d\.\d\.\d)/)[0]
|
206
|
-
elsif
|
206
|
+
elsif file_exist?("/etc/Eos-release")
|
207
207
|
platform "arista_eos"
|
208
|
-
platform_version
|
209
|
-
elsif
|
210
|
-
contents =
|
208
|
+
platform_version file_read("/etc/Eos-release").strip.split[-1]
|
209
|
+
elsif file_exist?("/etc/redhat-release")
|
210
|
+
contents = file_read("/etc/redhat-release").chomp
|
211
211
|
platform get_redhatish_platform(contents)
|
212
212
|
platform_version get_redhatish_version(contents)
|
213
|
-
elsif
|
214
|
-
contents =
|
213
|
+
elsif file_exist?("/etc/system-release")
|
214
|
+
contents = file_read("/etc/system-release").chomp
|
215
215
|
platform get_redhatish_platform(contents)
|
216
216
|
platform_version get_redhatish_version(contents)
|
217
|
-
elsif
|
218
|
-
suse_release =
|
217
|
+
elsif file_exist?("/etc/SuSE-release")
|
218
|
+
suse_release = file_read("/etc/SuSE-release")
|
219
219
|
suse_version = suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
|
220
220
|
suse_version = suse_release[/VERSION = ([\d\.]{2,})/, 1] if suse_version == ""
|
221
221
|
platform_version suse_version
|
@@ -243,16 +243,16 @@ Ohai.plugin(:Platform) do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
platform_version os_release_info["VERSION"]
|
246
|
-
elsif
|
246
|
+
elsif file_exist?("/etc/slackware-version")
|
247
247
|
platform "slackware"
|
248
|
-
platform_version
|
249
|
-
elsif
|
248
|
+
platform_version file_read("/etc/slackware-version").scan(/(\d+|\.+)/).join
|
249
|
+
elsif file_exist?("/etc/exherbo-release")
|
250
250
|
platform "exherbo"
|
251
251
|
# no way to determine platform_version in a rolling release distribution
|
252
252
|
# kernel release will be used - ex. 3.13
|
253
253
|
platform_version shell_out("/bin/uname -r").stdout.strip
|
254
|
-
elsif
|
255
|
-
contents =
|
254
|
+
elsif file_exist?("/usr/lib/os-release")
|
255
|
+
contents = file_read("/usr/lib/os-release")
|
256
256
|
if /clear-linux-os/.match?(contents) # Clear Linux https://clearlinux.org/
|
257
257
|
platform "clearlinux"
|
258
258
|
platform_version contents[/VERSION_ID=(\d+)/, 1]
|
@@ -285,14 +285,14 @@ Ohai.plugin(:Platform) do
|
|
285
285
|
def determine_os_version
|
286
286
|
# centos only includes the major version in os-release for some reason
|
287
287
|
if os_release_info["ID"] == "centos"
|
288
|
-
get_redhatish_version(
|
288
|
+
get_redhatish_version(file_read("/etc/redhat-release").chomp)
|
289
289
|
else
|
290
290
|
os_release_info["VERSION_ID"] || shell_out("/bin/uname -r").stdout.strip
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
294
294
|
collect_data(:linux) do
|
295
|
-
if
|
295
|
+
if file_exist?("/etc/os-release")
|
296
296
|
logger.trace("Plugin platform: Using /etc/os-release for platform detection")
|
297
297
|
|
298
298
|
# fixup os-release names to ohai platform names
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Thom May (<thom@clearairturbulence.org>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -51,15 +51,15 @@ Ohai.plugin(:Virtualization) do
|
|
51
51
|
# - may be able to determine if under paravirt from /dev/xen/evtchn (See OHAI-253)
|
52
52
|
# - Additional edge cases likely should not change the above assumptions
|
53
53
|
# but rather be additive - btm
|
54
|
-
if
|
54
|
+
if file_exist?("/proc/xen")
|
55
55
|
virtualization[:system] = "xen"
|
56
56
|
# Assume guest
|
57
57
|
virtualization[:role] = "guest"
|
58
58
|
virtualization[:systems][:xen] = "guest"
|
59
59
|
|
60
60
|
# This file should exist on most Xen systems, normally empty for guests
|
61
|
-
if
|
62
|
-
if /control_d/i.match?(
|
61
|
+
if file_exist?("/proc/xen/capabilities")
|
62
|
+
if /control_d/i.match?(file_read("/proc/xen/capabilities"))
|
63
63
|
logger.trace("Plugin Virtualization: /proc/xen/capabilities contains control_d. Detecting as Xen host")
|
64
64
|
virtualization[:role] = "host"
|
65
65
|
virtualization[:systems][:xen] = "host"
|
@@ -68,8 +68,8 @@ Ohai.plugin(:Virtualization) do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Detect Virtualbox from kernel module
|
71
|
-
if
|
72
|
-
modules =
|
71
|
+
if file_exist?("/proc/modules")
|
72
|
+
modules = file_read("/proc/modules")
|
73
73
|
if /^vboxdrv/.match?(modules)
|
74
74
|
logger.trace("Plugin Virtualization: /proc/modules contains vboxdrv. Detecting as vbox host")
|
75
75
|
virtualization[:system] = "vbox"
|
@@ -92,8 +92,8 @@ Ohai.plugin(:Virtualization) do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
# Detect paravirt KVM/QEMU from cpuinfo, report as KVM
|
95
|
-
if
|
96
|
-
if /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/.match?(
|
95
|
+
if file_exist?("/proc/cpuinfo")
|
96
|
+
if /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/.match?(file_read("/proc/cpuinfo"))
|
97
97
|
logger.trace("Plugin Virtualization: /proc/cpuinfo lists a KVM paravirt CPU string. Detecting as kvm guest")
|
98
98
|
virtualization[:system] = "kvm"
|
99
99
|
virtualization[:role] = "guest"
|
@@ -103,9 +103,9 @@ Ohai.plugin(:Virtualization) do
|
|
103
103
|
|
104
104
|
# Detect KVM systems via /sys
|
105
105
|
# guests will have the hypervisor cpu feature that hosts don't have
|
106
|
-
if
|
106
|
+
if file_exist?("/sys/devices/virtual/misc/kvm")
|
107
107
|
virtualization[:system] = "kvm"
|
108
|
-
if /hypervisor/.match?(
|
108
|
+
if /hypervisor/.match?(file_read("/proc/cpuinfo"))
|
109
109
|
logger.trace("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo lists the hypervisor feature. Detecting as kvm guest")
|
110
110
|
virtualization[:role] = "guest"
|
111
111
|
virtualization[:systems][:kvm] = "guest"
|
@@ -129,12 +129,12 @@ Ohai.plugin(:Virtualization) do
|
|
129
129
|
|
130
130
|
# Detect OpenVZ / Virtuozzo.
|
131
131
|
# http://wiki.openvz.org/BC_proc_entries
|
132
|
-
if
|
132
|
+
if file_exist?("/proc/bc/0")
|
133
133
|
logger.trace("Plugin Virtualization: /proc/bc/0 exists. Detecting as openvz host")
|
134
134
|
virtualization[:system] = "openvz"
|
135
135
|
virtualization[:role] = "host"
|
136
136
|
virtualization[:systems][:openvz] = "host"
|
137
|
-
elsif
|
137
|
+
elsif file_exist?("/proc/vz")
|
138
138
|
logger.trace("Plugin Virtualization: /proc/vz exists. Detecting as openvz guest")
|
139
139
|
virtualization[:system] = "openvz"
|
140
140
|
virtualization[:role] = "guest"
|
@@ -142,9 +142,9 @@ Ohai.plugin(:Virtualization) do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
# Detect Hyper-V guest and the hostname of the host
|
145
|
-
if
|
145
|
+
if file_exist?("/var/lib/hyperv/.kvp_pool_3")
|
146
146
|
logger.trace("Plugin Virtualization: /var/lib/hyperv/.kvp_pool_3 contains string indicating Hyper-V guest")
|
147
|
-
data =
|
147
|
+
data = file_read("/var/lib/hyperv/.kvp_pool_3")
|
148
148
|
hyperv_host = data[/\HostName(.*?)HostingSystemEditionId/, 1].scan(/[[:print:]]/).join.downcase
|
149
149
|
virtualization[:system] = "hyperv"
|
150
150
|
virtualization[:role] = "guest"
|
@@ -153,8 +153,8 @@ Ohai.plugin(:Virtualization) do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
# Detect Linux-VServer
|
156
|
-
if
|
157
|
-
proc_self_status =
|
156
|
+
if file_exist?("/proc/self/status")
|
157
|
+
proc_self_status = file_read("/proc/self/status")
|
158
158
|
vxid = proc_self_status.match(/^(s_context|VxID):\s*(\d+)$/)
|
159
159
|
if vxid && vxid[2]
|
160
160
|
virtualization[:system] = "linux-vserver"
|
@@ -188,8 +188,8 @@ Ohai.plugin(:Virtualization) do
|
|
188
188
|
#
|
189
189
|
# Full notes, https://tickets.opscode.com/browse/OHAI-551
|
190
190
|
# Kernel docs, https://www.kernel.org/doc/Documentation/cgroups
|
191
|
-
if
|
192
|
-
cgroup_content =
|
191
|
+
if file_exist?("/proc/self/cgroup")
|
192
|
+
cgroup_content = file_read("/proc/self/cgroup")
|
193
193
|
# These two REs catch many different examples. Here's a specific one
|
194
194
|
# from when it is docker and there is no subsystem name.
|
195
195
|
# https://rubular.com/r/dV13hiU9KxmiWB
|
@@ -199,17 +199,17 @@ Ohai.plugin(:Virtualization) do
|
|
199
199
|
virtualization[:system] = $1
|
200
200
|
virtualization[:role] = "guest"
|
201
201
|
virtualization[:systems][$1.to_sym] = "guest"
|
202
|
-
elsif /container=lxc/.match?(
|
202
|
+
elsif /container=lxc/.match?(file_read("/proc/1/environ"))
|
203
203
|
logger.trace("Plugin Virtualization: /proc/1/environ indicates lxc container. Detecting as lxc guest")
|
204
204
|
virtualization[:system] = "lxc"
|
205
205
|
virtualization[:role] = "guest"
|
206
206
|
virtualization[:systems][:lxc] = "guest"
|
207
|
-
elsif /container=systemd-nspawn/.match?(
|
207
|
+
elsif /container=systemd-nspawn/.match?(file_read("/proc/1/environ"))
|
208
208
|
logger.trace("Plugin Virtualization: /proc/1/environ indicates nspawn container. Detecting as nspawn guest")
|
209
209
|
virtualization[:system] = "nspawn"
|
210
210
|
virtualization[:role] = "guest"
|
211
211
|
virtualization[:systems][:nspawn] = "guest"
|
212
|
-
elsif lxc_version_exists? &&
|
212
|
+
elsif lxc_version_exists? && file_read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$}
|
213
213
|
# lxc-version shouldn't be installed by default
|
214
214
|
# Even so, it is likely we are on an LXC capable host that is not being used as such
|
215
215
|
# So we're cautious here to not overwrite other existing values (OHAI-573)
|
@@ -224,7 +224,7 @@ Ohai.plugin(:Virtualization) do
|
|
224
224
|
# If so, we may need to look further for a differentiator (OHAI-573)
|
225
225
|
virtualization[:systems][:lxc] = "host"
|
226
226
|
end
|
227
|
-
elsif
|
227
|
+
elsif file_exist?("/.dockerenv") || file_exist?("/.dockerinit")
|
228
228
|
logger.trace("Plugin Virtualization: .dockerenv or .dockerinit exist. Detecting as docker guest")
|
229
229
|
virtualization[:system] = "docker"
|
230
230
|
virtualization[:role] = "guest"
|
@@ -233,7 +233,7 @@ Ohai.plugin(:Virtualization) do
|
|
233
233
|
|
234
234
|
# Detect LXD
|
235
235
|
# See https://github.com/lxc/lxd/blob/master/doc/dev-lxd.md
|
236
|
-
if
|
236
|
+
if file_exist?("/dev/lxd/sock")
|
237
237
|
logger.trace("Plugin Virtualization: /dev/lxd/sock exists. Detecting as lxd guest")
|
238
238
|
virtualization[:system] = "lxd"
|
239
239
|
virtualization[:role] = "guest"
|
@@ -248,7 +248,7 @@ Ohai.plugin(:Virtualization) do
|
|
248
248
|
# Snap based installations utilize '/var/snap/lxd/common/lxd/'
|
249
249
|
# - includes all future releases starting with 2.21, and will be the only source of 3.1+ feature releases post-bionic
|
250
250
|
["/var/lib/lxd/devlxd", "/var/snap/lxd/common/lxd/devlxd"].each do |devlxd|
|
251
|
-
if
|
251
|
+
if file_exist?(devlxd)
|
252
252
|
logger.trace("Plugin Virtualization: #{devlxd} exists. Detecting as lxd host")
|
253
253
|
virtualization[:system] = "lxd"
|
254
254
|
virtualization[:role] = "host"
|