ohai 16.4.11 → 16.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +11 -6
  3. data/bin/ohai +1 -1
  4. data/lib/ohai.rb +1 -1
  5. data/lib/ohai/application.rb +39 -0
  6. data/lib/ohai/common/dmi.rb +7 -3
  7. data/lib/ohai/config.rb +2 -3
  8. data/lib/ohai/dsl.rb +1 -1
  9. data/lib/ohai/dsl/plugin.rb +12 -5
  10. data/lib/ohai/dsl/plugin/versionvii.rb +28 -16
  11. data/lib/ohai/exception.rb +1 -1
  12. data/lib/ohai/hints.rb +1 -1
  13. data/lib/ohai/loader.rb +1 -1
  14. data/lib/ohai/log.rb +1 -1
  15. data/lib/ohai/mixin/azure_metadata.rb +1 -1
  16. data/lib/ohai/mixin/chef_utils_wiring.rb +51 -0
  17. data/lib/ohai/mixin/command.rb +3 -54
  18. data/lib/ohai/mixin/constant_helper.rb +1 -1
  19. data/lib/ohai/mixin/dmi_decode.rb +1 -1
  20. data/lib/ohai/mixin/do_metadata.rb +1 -1
  21. data/lib/ohai/mixin/ec2_metadata.rb +3 -3
  22. data/lib/ohai/mixin/http_helper.rb +1 -1
  23. data/lib/ohai/mixin/network_helper.rb +1 -1
  24. data/lib/ohai/mixin/os.rb +67 -2
  25. data/lib/ohai/mixin/scaleway_metadata.rb +1 -1
  26. data/lib/ohai/mixin/seconds_to_human.rb +1 -1
  27. data/lib/ohai/mixin/shell_out.rb +50 -0
  28. data/lib/ohai/mixin/string.rb +1 -1
  29. data/lib/ohai/mixin/train_helpers.rb +35 -0
  30. data/lib/ohai/mixin/which.rb +38 -0
  31. data/lib/ohai/plugin_config.rb +1 -1
  32. data/lib/ohai/plugins/aix/kernel.rb +1 -1
  33. data/lib/ohai/plugins/aix/memory.rb +3 -3
  34. data/lib/ohai/plugins/aix/network.rb +1 -1
  35. data/lib/ohai/plugins/aix/platform.rb +1 -1
  36. data/lib/ohai/plugins/aix/uptime.rb +1 -1
  37. data/lib/ohai/plugins/aix/virtualization.rb +1 -1
  38. data/lib/ohai/plugins/azure.rb +25 -5
  39. data/lib/ohai/plugins/bsd/virtualization.rb +3 -3
  40. data/lib/ohai/plugins/chef.rb +1 -1
  41. data/lib/ohai/plugins/cloud.rb +1 -1
  42. data/lib/ohai/plugins/command.rb +1 -1
  43. data/lib/ohai/plugins/cpu.rb +6 -6
  44. data/lib/ohai/plugins/darwin/memory.rb +1 -1
  45. data/lib/ohai/plugins/darwin/network.rb +1 -1
  46. data/lib/ohai/plugins/darwin/platform.rb +2 -2
  47. data/lib/ohai/plugins/darwin/virtualization.rb +2 -2
  48. data/lib/ohai/plugins/dmi.rb +1 -1
  49. data/lib/ohai/plugins/docker.rb +1 -1
  50. data/lib/ohai/plugins/ec2.rb +15 -9
  51. data/lib/ohai/plugins/erlang.rb +1 -1
  52. data/lib/ohai/plugins/eucalyptus.rb +1 -1
  53. data/lib/ohai/plugins/filesystem.rb +4 -4
  54. data/lib/ohai/plugins/fips.rb +1 -1
  55. data/lib/ohai/plugins/gce.rb +2 -2
  56. data/lib/ohai/plugins/hostname.rb +1 -1
  57. data/lib/ohai/plugins/init_package.rb +2 -2
  58. data/lib/ohai/plugins/java.rb +1 -1
  59. data/lib/ohai/plugins/joyent.rb +2 -2
  60. data/lib/ohai/plugins/kernel.rb +9 -5
  61. data/lib/ohai/plugins/keys.rb +1 -1
  62. data/lib/ohai/plugins/languages.rb +1 -1
  63. data/lib/ohai/plugins/libvirt.rb +1 -1
  64. data/lib/ohai/plugins/linode.rb +1 -1
  65. data/lib/ohai/plugins/linux/block_device.rb +9 -9
  66. data/lib/ohai/plugins/linux/interrupts.rb +3 -3
  67. data/lib/ohai/plugins/linux/ipc.rb +1 -1
  68. data/lib/ohai/plugins/linux/lsb.rb +4 -4
  69. data/lib/ohai/plugins/linux/machineid.rb +4 -4
  70. data/lib/ohai/plugins/linux/mdadm.rb +2 -2
  71. data/lib/ohai/plugins/linux/memory.rb +2 -2
  72. data/lib/ohai/plugins/linux/network.rb +13 -13
  73. data/lib/ohai/plugins/linux/platform.rb +30 -30
  74. data/lib/ohai/plugins/linux/virtualization.rb +24 -24
  75. data/lib/ohai/plugins/network.rb +1 -1
  76. data/lib/ohai/plugins/ohai_time.rb +2 -2
  77. data/lib/ohai/plugins/openstack.rb +1 -1
  78. data/lib/ohai/plugins/os.rb +5 -1
  79. data/lib/ohai/plugins/packages.rb +20 -0
  80. data/lib/ohai/plugins/passwd.rb +57 -1
  81. data/lib/ohai/plugins/perl.rb +1 -1
  82. data/lib/ohai/plugins/platform.rb +1 -1
  83. data/lib/ohai/plugins/powershell.rb +1 -1
  84. data/lib/ohai/plugins/ps.rb +1 -1
  85. data/lib/ohai/plugins/python.rb +1 -1
  86. data/lib/ohai/plugins/rackspace.rb +2 -2
  87. data/lib/ohai/plugins/scaleway.rb +1 -1
  88. data/lib/ohai/plugins/shard.rb +1 -1
  89. data/lib/ohai/plugins/shells.rb +3 -3
  90. data/lib/ohai/plugins/softlayer.rb +1 -1
  91. data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
  92. data/lib/ohai/plugins/solaris2/network.rb +6 -8
  93. data/lib/ohai/plugins/solaris2/platform.rb +3 -3
  94. data/lib/ohai/plugins/solaris2/virtualization.rb +2 -2
  95. data/lib/ohai/plugins/ssh_host_key.rb +13 -13
  96. data/lib/ohai/plugins/train.rb +35 -0
  97. data/lib/ohai/plugins/uptime.rb +2 -2
  98. data/lib/ohai/plugins/virtualbox.rb +1 -1
  99. data/lib/ohai/plugins/vmware.rb +2 -2
  100. data/lib/ohai/plugins/windows/drivers.rb +1 -1
  101. data/lib/ohai/plugins/windows/network.rb +2 -2
  102. data/lib/ohai/plugins/windows/platform.rb +1 -1
  103. data/lib/ohai/plugins/windows/system_enclosure.rb +1 -1
  104. data/lib/ohai/plugins/windows/virtualization.rb +1 -1
  105. data/lib/ohai/plugins/zpools.rb +1 -1
  106. data/lib/ohai/provides_map.rb +1 -1
  107. data/lib/ohai/runner.rb +5 -1
  108. data/lib/ohai/system.rb +34 -7
  109. data/lib/ohai/train_transport.rb +28 -0
  110. data/lib/ohai/util/file_helper.rb +4 -37
  111. data/lib/ohai/util/win32.rb +1 -1
  112. data/lib/ohai/version.rb +3 -3
  113. data/ohai.gemspec +7 -7
  114. 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 = 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
@@ -41,7 +41,7 @@ Ohai.plugin(:IPC) do
41
41
  "perms" => parts[3],
42
42
  "bytes" => parts[4].to_i,
43
43
  "nattch" => parts[5].to_i,
44
- "status" => parts[6] ? parts[6] : "",
44
+ "status" => parts[6] || "",
45
45
  }
46
46
 
47
47
  ipc["shm"][parts[1].to_i] = segment
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
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 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+/)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
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
- 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}"
@@ -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) 2008-2017, Chef Software Inc.
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
- 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)
@@ -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
- if iv[:routes]
145
- iv[:routes].collect do |r|
146
- r.merge(dev: i) if r[:family] == family[:name]
147
- end.compact
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 = "#{key.downcase.tr(" ", "_")}"
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 = "#{key.downcase.tr(" ", "_")}"
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] ? default_route[:via] : family[:default_route].chomp("/0")
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) 2015-2017, Chef Software Inc.
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 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
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Thom May (<thom@clearairturbulence.org>)
3
- # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
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 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"