ohai 16.5.6 → 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 +4 -0
- data/lib/ohai/application.rb +39 -0
- data/lib/ohai/common/dmi.rb +7 -3
- data/lib/ohai/dsl/plugin.rb +7 -0
- data/lib/ohai/dsl/plugin/versionvii.rb +27 -15
- data/lib/ohai/mixin/chef_utils_wiring.rb +13 -1
- data/lib/ohai/mixin/os.rb +66 -1
- data/lib/ohai/mixin/train_helpers.rb +35 -0
- data/lib/ohai/plugins/azure.rb +24 -4
- data/lib/ohai/plugins/bsd/virtualization.rb +1 -1
- data/lib/ohai/plugins/chef.rb +1 -1
- data/lib/ohai/plugins/cpu.rb +4 -4
- data/lib/ohai/plugins/darwin/virtualization.rb +1 -1
- data/lib/ohai/plugins/dmi.rb +1 -1
- data/lib/ohai/plugins/ec2.rb +13 -7
- data/lib/ohai/plugins/filesystem.rb +3 -3
- data/lib/ohai/plugins/gce.rb +2 -2
- data/lib/ohai/plugins/init_package.rb +1 -1
- data/lib/ohai/plugins/joyent.rb +2 -2
- data/lib/ohai/plugins/kernel.rb +7 -3
- data/lib/ohai/plugins/linux/block_device.rb +8 -8
- data/lib/ohai/plugins/linux/interrupts.rb +3 -3
- data/lib/ohai/plugins/linux/lsb.rb +3 -3
- 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 +1 -1
- data/lib/ohai/plugins/linux/network.rb +3 -3
- data/lib/ohai/plugins/linux/platform.rb +29 -29
- data/lib/ohai/plugins/linux/virtualization.rb +23 -23
- data/lib/ohai/plugins/ohai_time.rb +1 -1
- data/lib/ohai/plugins/os.rb +4 -0
- data/lib/ohai/plugins/passwd.rb +57 -1
- data/lib/ohai/plugins/scaleway.rb +1 -1
- data/lib/ohai/plugins/shells.rb +2 -2
- data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
- data/lib/ohai/plugins/solaris2/platform.rb +2 -2
- data/lib/ohai/plugins/solaris2/virtualization.rb +1 -1
- data/lib/ohai/plugins/ssh_host_key.rb +12 -12
- data/lib/ohai/plugins/train.rb +35 -0
- data/lib/ohai/plugins/uptime.rb +1 -1
- data/lib/ohai/plugins/vmware.rb +1 -1
- data/lib/ohai/runner.rb +4 -0
- data/lib/ohai/system.rb +32 -4
- data/lib/ohai/train_transport.rb +28 -0
- data/lib/ohai/version.rb +1 -1
- data/ohai.gemspec +2 -1
- metadata +20 -3
data/lib/ohai/plugins/dmi.rb
CHANGED
@@ -76,7 +76,7 @@ Ohai.plugin(:DMI) do
|
|
76
76
|
dmi[:table_location] = table_location[1]
|
77
77
|
|
78
78
|
elsif ( handle = handle_line.match(line) )
|
79
|
-
unless Ohai::Common::DMI.
|
79
|
+
unless Ohai::Common::DMI.allowlisted_ids.include?(handle[2].to_i)
|
80
80
|
dmi_record = nil
|
81
81
|
next
|
82
82
|
end
|
data/lib/ohai/plugins/ec2.rb
CHANGED
@@ -97,8 +97,8 @@ Ohai.plugin(:EC2) do
|
|
97
97
|
# @param path[String] abs path to the file
|
98
98
|
# @return [String] contents of the file if it exists
|
99
99
|
def file_val_if_exists(path)
|
100
|
-
if
|
101
|
-
|
100
|
+
if file_exist?(path)
|
101
|
+
file_read(path)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -122,11 +122,17 @@ Ohai.plugin(:EC2) do
|
|
122
122
|
fetch_metadata.each do |k, v|
|
123
123
|
# fetch_metadata returns IAM security credentials, including the IAM user's
|
124
124
|
# secret access key. We'd rather not have ohai send this information
|
125
|
-
# to the server.
|
126
|
-
#
|
127
|
-
|
128
|
-
|
129
|
-
|
125
|
+
# to the server. If the instance is associated with an IAM role we grab
|
126
|
+
# only the "info" key and the IAM role name.
|
127
|
+
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
|
128
|
+
if k == "iam" && !hint?("iam")
|
129
|
+
ec2[:iam] = v.select { |key, value| key == "info" }
|
130
|
+
if v["security-credentials"] && v["security-credentials"].keys.length == 1
|
131
|
+
ec2[:iam]["role_name"] = v["security-credentials"].keys[0]
|
132
|
+
end
|
133
|
+
else
|
134
|
+
ec2[k] = v
|
135
|
+
end
|
130
136
|
end
|
131
137
|
ec2[:userdata] = fetch_userdata
|
132
138
|
ec2[:account_id] = fetch_dynamic_data["accountId"]
|
@@ -29,7 +29,7 @@ Ohai.plugin(:Filesystem) do
|
|
29
29
|
def find_device(name)
|
30
30
|
%w{/dev /dev/mapper}.each do |dir|
|
31
31
|
path = File.join(dir, name)
|
32
|
-
return path if
|
32
|
+
return path if file_exist?(path)
|
33
33
|
end
|
34
34
|
name
|
35
35
|
end
|
@@ -371,11 +371,11 @@ Ohai.plugin(:Filesystem) do
|
|
371
371
|
end
|
372
372
|
|
373
373
|
# Grab any missing mount information from /proc/mounts
|
374
|
-
if
|
374
|
+
if file_exist?("/proc/mounts")
|
375
375
|
mounts = ""
|
376
376
|
# Due to https://tickets.opscode.com/browse/OHAI-196
|
377
377
|
# we have to non-block read dev files. Ew.
|
378
|
-
f =
|
378
|
+
f = file_open("/proc/mounts")
|
379
379
|
loop do
|
380
380
|
data = f.read_nonblock(4096)
|
381
381
|
mounts << data
|
data/lib/ohai/plugins/gce.rb
CHANGED
@@ -40,8 +40,8 @@ Ohai.plugin(:GCE) do
|
|
40
40
|
# @param path[String] abs path to the file
|
41
41
|
# @return [String] contents of the file if it exists
|
42
42
|
def file_val_if_exists(path)
|
43
|
-
if
|
44
|
-
|
43
|
+
if file_exist?(path)
|
44
|
+
file_read(path)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -20,6 +20,6 @@ Ohai.plugin(:InitPackage) do
|
|
20
20
|
provides "init_package"
|
21
21
|
|
22
22
|
collect_data(:linux) do
|
23
|
-
init_package
|
23
|
+
init_package file_exist?("/proc/1/comm") ? file_open("/proc/1/comm").gets.chomp : "init"
|
24
24
|
end
|
25
25
|
end
|
data/lib/ohai/plugins/joyent.rb
CHANGED
@@ -25,7 +25,7 @@ Ohai.plugin(:Joyent) do
|
|
25
25
|
depends "os", "platform", "virtualization"
|
26
26
|
|
27
27
|
def collect_product_file
|
28
|
-
data =
|
28
|
+
data = file_read("/etc/product") rescue nil
|
29
29
|
if data
|
30
30
|
data.strip.split("\n")
|
31
31
|
else
|
@@ -34,7 +34,7 @@ Ohai.plugin(:Joyent) do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def collect_pkgsrc
|
37
|
-
data =
|
37
|
+
data = file_read("/opt/local/etc/pkg_install.conf") rescue nil
|
38
38
|
if data
|
39
39
|
/PKG_PATH=(.*)/.match(data)[1] rescue nil
|
40
40
|
end
|
data/lib/ohai/plugins/kernel.rb
CHANGED
@@ -156,6 +156,10 @@ Ohai.plugin(:Kernel) do
|
|
156
156
|
].include?(name)
|
157
157
|
end
|
158
158
|
|
159
|
+
collect_data(:target) do
|
160
|
+
# intentionally left blank
|
161
|
+
end
|
162
|
+
|
159
163
|
collect_data(:default) do
|
160
164
|
kernel init_kernel
|
161
165
|
end
|
@@ -204,8 +208,8 @@ Ohai.plugin(:Kernel) do
|
|
204
208
|
if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
|
205
209
|
modules[$1] = { size: $2, refcount: $3 }
|
206
210
|
# Making sure to get the module version that has been loaded
|
207
|
-
if
|
208
|
-
version =
|
211
|
+
if file_exist?("/sys/module/#{$1}/version")
|
212
|
+
version = file_read("/sys/module/#{$1}/version").chomp.strip
|
209
213
|
modules[$1]["version"] = version unless version.empty?
|
210
214
|
end
|
211
215
|
end
|
@@ -230,7 +234,7 @@ Ohai.plugin(:Kernel) do
|
|
230
234
|
so = shell_out("uname -s")
|
231
235
|
kernel[:os] = so.stdout.split($/)[0]
|
232
236
|
|
233
|
-
so =
|
237
|
+
so = file_open("/etc/release", &:gets)
|
234
238
|
md = /(?<update>\d.*\d)/.match(so)
|
235
239
|
kernel[:update] = md[:update] if md
|
236
240
|
|
@@ -20,24 +20,24 @@ Ohai.plugin(:BlockDevice) do
|
|
20
20
|
provides "block_device"
|
21
21
|
|
22
22
|
collect_data(:linux) do
|
23
|
-
if
|
23
|
+
if file_exist?("/sys/block")
|
24
24
|
block = Mash.new
|
25
|
-
|
25
|
+
dir_glob("/sys/block/*").each do |block_device_dir|
|
26
26
|
dir = File.basename(block_device_dir)
|
27
27
|
block[dir] = Mash.new
|
28
28
|
%w{size removable}.each do |check|
|
29
|
-
if
|
30
|
-
|
29
|
+
if file_exist?("/sys/block/#{dir}/#{check}")
|
30
|
+
file_open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
|
31
31
|
end
|
32
32
|
end
|
33
33
|
%w{model rev state timeout vendor queue_depth}.each do |check|
|
34
|
-
if
|
35
|
-
|
34
|
+
if file_exist?("/sys/block/#{dir}/device/#{check}")
|
35
|
+
file_open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
|
36
36
|
end
|
37
37
|
end
|
38
38
|
%w{rotational physical_block_size logical_block_size}.each do |check|
|
39
|
-
if
|
40
|
-
|
39
|
+
if file_exist?("/sys/block/#{dir}/queue/#{check}")
|
40
|
+
file_open("/sys/block/#{dir}/queue/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -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
|
@@ -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+/)
|
@@ -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}"
|
@@ -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)
|
@@ -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
|
@@ -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"
|