ohai 16.5.6 → 16.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/lib/ohai/application.rb +39 -0
  4. data/lib/ohai/common/dmi.rb +7 -3
  5. data/lib/ohai/dsl/plugin.rb +7 -0
  6. data/lib/ohai/dsl/plugin/versionvii.rb +27 -15
  7. data/lib/ohai/mixin/chef_utils_wiring.rb +13 -1
  8. data/lib/ohai/mixin/os.rb +66 -1
  9. data/lib/ohai/mixin/train_helpers.rb +35 -0
  10. data/lib/ohai/plugins/azure.rb +24 -4
  11. data/lib/ohai/plugins/bsd/virtualization.rb +1 -1
  12. data/lib/ohai/plugins/chef.rb +1 -1
  13. data/lib/ohai/plugins/cpu.rb +4 -4
  14. data/lib/ohai/plugins/darwin/virtualization.rb +1 -1
  15. data/lib/ohai/plugins/dmi.rb +1 -1
  16. data/lib/ohai/plugins/ec2.rb +13 -7
  17. data/lib/ohai/plugins/filesystem.rb +3 -3
  18. data/lib/ohai/plugins/gce.rb +2 -2
  19. data/lib/ohai/plugins/init_package.rb +1 -1
  20. data/lib/ohai/plugins/joyent.rb +2 -2
  21. data/lib/ohai/plugins/kernel.rb +7 -3
  22. data/lib/ohai/plugins/linux/block_device.rb +8 -8
  23. data/lib/ohai/plugins/linux/interrupts.rb +3 -3
  24. data/lib/ohai/plugins/linux/lsb.rb +3 -3
  25. data/lib/ohai/plugins/linux/machineid.rb +4 -4
  26. data/lib/ohai/plugins/linux/mdadm.rb +2 -2
  27. data/lib/ohai/plugins/linux/memory.rb +1 -1
  28. data/lib/ohai/plugins/linux/network.rb +3 -3
  29. data/lib/ohai/plugins/linux/platform.rb +29 -29
  30. data/lib/ohai/plugins/linux/virtualization.rb +23 -23
  31. data/lib/ohai/plugins/ohai_time.rb +1 -1
  32. data/lib/ohai/plugins/os.rb +4 -0
  33. data/lib/ohai/plugins/passwd.rb +57 -1
  34. data/lib/ohai/plugins/scaleway.rb +1 -1
  35. data/lib/ohai/plugins/shells.rb +2 -2
  36. data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
  37. data/lib/ohai/plugins/solaris2/platform.rb +2 -2
  38. data/lib/ohai/plugins/solaris2/virtualization.rb +1 -1
  39. data/lib/ohai/plugins/ssh_host_key.rb +12 -12
  40. data/lib/ohai/plugins/train.rb +35 -0
  41. data/lib/ohai/plugins/uptime.rb +1 -1
  42. data/lib/ohai/plugins/vmware.rb +1 -1
  43. data/lib/ohai/runner.rb +4 -0
  44. data/lib/ohai/system.rb +32 -4
  45. data/lib/ohai/train_transport.rb +28 -0
  46. data/lib/ohai/version.rb +1 -1
  47. data/ohai.gemspec +2 -1
  48. metadata +20 -3
@@ -35,7 +35,7 @@ Ohai.plugin(:Virtualization) do
35
35
  end
36
36
 
37
37
  def fusion_exists?
38
- ::File.exist?("/Applications/VMware\ Fusion.app/")
38
+ file_exist?("/Applications/VMware\ Fusion.app/")
39
39
  end
40
40
 
41
41
  def docker_exists?
@@ -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.whitelisted_ids.include?(handle[2].to_i)
79
+ unless Ohai::Common::DMI.allowlisted_ids.include?(handle[2].to_i)
80
80
  dmi_record = nil
81
81
  next
82
82
  end
@@ -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 ::File.exist?(path)
101
- ::File.read(path)
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
- # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
127
- next if k == "iam" && !hint?("iam")
128
-
129
- ec2[k] = v
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 File.exist?(path)
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 File.exist?("/proc/mounts")
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 = File.open("/proc/mounts")
378
+ f = file_open("/proc/mounts")
379
379
  loop do
380
380
  data = f.read_nonblock(4096)
381
381
  mounts << data
@@ -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 ::File.exist?(path)
44
- ::File.read(path)
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 File.exist?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : "init"
23
+ init_package file_exist?("/proc/1/comm") ? file_open("/proc/1/comm").gets.chomp : "init"
24
24
  end
25
25
  end
@@ -25,7 +25,7 @@ Ohai.plugin(:Joyent) do
25
25
  depends "os", "platform", "virtualization"
26
26
 
27
27
  def collect_product_file
28
- data = ::File.read("/etc/product") rescue nil
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 = ::File.read("/opt/local/etc/pkg_install.conf") rescue nil
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
@@ -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 File.exist?("/sys/module/#{$1}/version")
208
- version = File.read("/sys/module/#{$1}/version").chomp.strip
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 = File.open("/etc/release", &:gets)
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 File.exist?("/sys/block")
23
+ if file_exist?("/sys/block")
24
24
  block = Mash.new
25
- Dir["/sys/block/*"].each do |block_device_dir|
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 File.exist?("/sys/block/#{dir}/#{check}")
30
- File.open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
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 File.exist?("/sys/block/#{dir}/device/#{check}")
35
- File.open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
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 File.exist?("/sys/block/#{dir}/queue/#{check}")
40
- File.open("/sys/block/#{dir}/queue/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
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 = File.read(path).strip
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
- File.open("/proc/interrupts").each do |line|
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 File.exist?("/proc/irq/#{irqn}/smp_affinity")
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 File.exist?("/usr/bin/lsb_release")
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 File.exist?("/etc/lsb-release")
41
+ elsif file_exist?("/etc/lsb-release")
42
42
  # Old, non-standard Debian support
43
- File.open("/etc/lsb-release").each do |line|
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 ::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
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 File.exist?("/proc/mdstat")
56
+ if file_exist?("/proc/mdstat")
57
57
  devices = {}
58
- File.open("/proc/mdstat").each do |line|
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
- File.open("/proc/meminfo").each do |line|
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
- File.exist? "/proc/net/if_inet6"
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 ||= ::File.directory?("/proc/vz")
46
+ @openvz ||= file_directory?("/proc/vz")
47
47
  end
48
48
 
49
49
  def is_openvz_host?
50
- is_openvz? && ::File.directory?("/proc/bc")
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 File.exist?(file)
46
+ return nil unless file_exist?(file)
47
47
 
48
- File.read(file).split.inject({}) do |map, line|
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 && File.exist?(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
- File.exist?("/etc/os-release") && os_release_info["CISCO_RELEASE_INFO"]
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 = File.read("/etc/f5-release")
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 File.exist?("/etc/oracle-release")
182
- contents = File.read("/etc/oracle-release").chomp
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 File.exist?("/etc/enterprise-release")
186
- contents = File.read("/etc/enterprise-release").chomp
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 File.exist?("/etc/f5-release")
189
+ elsif file_exist?("/etc/f5-release")
190
190
  platform "bigip"
191
191
  platform_version bigip_version
192
- elsif File.exist?("/etc/debian_version")
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 File.read("/etc/debian_version").chomp
200
+ platform_version file_read("/etc/debian_version").chomp
201
201
  end
202
- elsif File.exist?("/etc/parallels-release")
203
- contents = File.read("/etc/parallels-release").chomp
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 File.exist?("/etc/Eos-release")
206
+ elsif file_exist?("/etc/Eos-release")
207
207
  platform "arista_eos"
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
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 File.exist?("/etc/system-release")
214
- contents = File.read("/etc/system-release").chomp
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 File.exist?("/etc/SuSE-release")
218
- suse_release = File.read("/etc/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 File.exist?("/etc/slackware-version")
246
+ elsif file_exist?("/etc/slackware-version")
247
247
  platform "slackware"
248
- platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
249
- elsif File.exist?("/etc/exherbo-release")
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 File.exist?("/usr/lib/os-release")
255
- contents = File.read("/usr/lib/os-release")
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(File.read("/etc/redhat-release").chomp)
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 ::File.exist?("/etc/os-release")
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 File.exist?("/proc/xen")
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 File.exist?("/proc/xen/capabilities")
62
- if /control_d/i.match?(File.read("/proc/xen/capabilities"))
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 File.exist?("/proc/modules")
72
- modules = File.read("/proc/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 File.exist?("/proc/cpuinfo")
96
- if /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/.match?(File.read("/proc/cpuinfo"))
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 File.exist?("/sys/devices/virtual/misc/kvm")
106
+ if file_exist?("/sys/devices/virtual/misc/kvm")
107
107
  virtualization[:system] = "kvm"
108
- if /hypervisor/.match?(File.read("/proc/cpuinfo"))
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 File.exist?("/proc/bc/0")
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 File.exist?("/proc/vz")
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 File.exist?("/var/lib/hyperv/.kvp_pool_3")
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 = File.read("/var/lib/hyperv/.kvp_pool_3")
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 File.exist?("/proc/self/status")
157
- proc_self_status = File.read("/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 File.exist?("/proc/self/cgroup")
192
- cgroup_content = File.read("/proc/self/cgroup")
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?(File.read("/proc/1/environ"))
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?(File.read("/proc/1/environ"))
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? && File.read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$}
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 File.exist?("/.dockerenv") || File.exist?("/.dockerinit")
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 File.exist?("/dev/lxd/sock")
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 File.exist?(devlxd)
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"