ohai 16.3.2 → 16.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -4
  3. data/bin/ohai +1 -1
  4. data/lib/ohai.rb +1 -1
  5. data/lib/ohai/application.rb +2 -2
  6. data/lib/ohai/config.rb +2 -3
  7. data/lib/ohai/dsl.rb +1 -1
  8. data/lib/ohai/dsl/plugin.rb +5 -5
  9. data/lib/ohai/dsl/plugin/versionvii.rb +1 -1
  10. data/lib/ohai/exception.rb +1 -1
  11. data/lib/ohai/hints.rb +1 -1
  12. data/lib/ohai/loader.rb +2 -3
  13. data/lib/ohai/log.rb +2 -2
  14. data/lib/ohai/mixin/azure_metadata.rb +1 -1
  15. data/lib/ohai/mixin/chef_utils_wiring.rb +39 -0
  16. data/lib/ohai/mixin/command.rb +3 -54
  17. data/lib/ohai/mixin/constant_helper.rb +1 -1
  18. data/lib/ohai/mixin/dmi_decode.rb +1 -1
  19. data/lib/ohai/mixin/do_metadata.rb +1 -1
  20. data/lib/ohai/mixin/ec2_metadata.rb +3 -3
  21. data/lib/ohai/mixin/http_helper.rb +1 -1
  22. data/lib/ohai/mixin/network_helper.rb +1 -1
  23. data/lib/ohai/mixin/os.rb +2 -2
  24. data/lib/ohai/mixin/scaleway_metadata.rb +1 -1
  25. data/lib/ohai/mixin/seconds_to_human.rb +1 -1
  26. data/lib/ohai/mixin/shell_out.rb +50 -0
  27. data/lib/ohai/mixin/softlayer_metadata.rb +1 -1
  28. data/lib/ohai/mixin/string.rb +1 -1
  29. data/lib/ohai/mixin/which.rb +38 -0
  30. data/lib/ohai/plugin_config.rb +1 -1
  31. data/lib/ohai/plugins/aix/kernel.rb +1 -1
  32. data/lib/ohai/plugins/aix/memory.rb +3 -3
  33. data/lib/ohai/plugins/aix/network.rb +3 -2
  34. data/lib/ohai/plugins/aix/platform.rb +1 -1
  35. data/lib/ohai/plugins/aix/uptime.rb +2 -2
  36. data/lib/ohai/plugins/aix/virtualization.rb +1 -1
  37. data/lib/ohai/plugins/azure.rb +1 -1
  38. data/lib/ohai/plugins/bsd/virtualization.rb +2 -2
  39. data/lib/ohai/plugins/cloud.rb +2 -2
  40. data/lib/ohai/plugins/command.rb +1 -1
  41. data/lib/ohai/plugins/cpu.rb +3 -3
  42. data/lib/ohai/plugins/darwin/memory.rb +1 -1
  43. data/lib/ohai/plugins/darwin/network.rb +1 -1
  44. data/lib/ohai/plugins/darwin/platform.rb +2 -2
  45. data/lib/ohai/plugins/darwin/virtualization.rb +1 -1
  46. data/lib/ohai/plugins/docker.rb +3 -3
  47. data/lib/ohai/plugins/dragonflybsd/platform.rb +2 -4
  48. data/lib/ohai/plugins/ec2.rb +4 -3
  49. data/lib/ohai/plugins/erlang.rb +1 -1
  50. data/lib/ohai/plugins/eucalyptus.rb +1 -1
  51. data/lib/ohai/plugins/filesystem.rb +8 -14
  52. data/lib/ohai/plugins/fips.rb +2 -6
  53. data/lib/ohai/plugins/freebsd/platform.rb +2 -4
  54. data/lib/ohai/plugins/gce.rb +1 -1
  55. data/lib/ohai/plugins/hostname.rb +5 -5
  56. data/lib/ohai/plugins/init_package.rb +1 -1
  57. data/lib/ohai/plugins/java.rb +1 -1
  58. data/lib/ohai/plugins/kernel.rb +3 -3
  59. data/lib/ohai/plugins/keys.rb +1 -1
  60. data/lib/ohai/plugins/languages.rb +1 -1
  61. data/lib/ohai/plugins/libvirt.rb +1 -1
  62. data/lib/ohai/plugins/linode.rb +1 -1
  63. data/lib/ohai/plugins/linux/block_device.rb +1 -1
  64. data/lib/ohai/plugins/linux/hostnamectl.rb +1 -2
  65. data/lib/ohai/plugins/linux/ipc.rb +1 -1
  66. data/lib/ohai/plugins/linux/lsb.rb +2 -3
  67. data/lib/ohai/plugins/linux/lspci.rb +1 -2
  68. data/lib/ohai/plugins/linux/machineid.rb +2 -2
  69. data/lib/ohai/plugins/linux/memory.rb +1 -1
  70. data/lib/ohai/plugins/linux/network.rb +21 -13
  71. data/lib/ohai/plugins/linux/platform.rb +15 -18
  72. data/lib/ohai/plugins/linux/virtualization.rb +1 -1
  73. data/lib/ohai/plugins/netbsd/network.rb +4 -8
  74. data/lib/ohai/plugins/netbsd/platform.rb +2 -4
  75. data/lib/ohai/plugins/network.rb +5 -4
  76. data/lib/ohai/plugins/ohai_time.rb +1 -1
  77. data/lib/ohai/plugins/openbsd/network.rb +4 -8
  78. data/lib/ohai/plugins/openbsd/platform.rb +2 -4
  79. data/lib/ohai/plugins/openstack.rb +3 -2
  80. data/lib/ohai/plugins/os.rb +1 -1
  81. data/lib/ohai/plugins/packages.rb +21 -1
  82. data/lib/ohai/plugins/passwd.rb +2 -1
  83. data/lib/ohai/plugins/perl.rb +1 -1
  84. data/lib/ohai/plugins/platform.rb +1 -1
  85. data/lib/ohai/plugins/powershell.rb +1 -1
  86. data/lib/ohai/plugins/ps.rb +1 -1
  87. data/lib/ohai/plugins/python.rb +1 -1
  88. data/lib/ohai/plugins/rackspace.rb +5 -4
  89. data/lib/ohai/plugins/root_group.rb +1 -1
  90. data/lib/ohai/plugins/ruby.rb +4 -15
  91. data/lib/ohai/plugins/scaleway.rb +1 -1
  92. data/lib/ohai/plugins/shard.rb +2 -2
  93. data/lib/ohai/plugins/shells.rb +1 -1
  94. data/lib/ohai/plugins/softlayer.rb +1 -1
  95. data/lib/ohai/plugins/solaris2/dmi.rb +2 -3
  96. data/lib/ohai/plugins/solaris2/memory.rb +1 -2
  97. data/lib/ohai/plugins/solaris2/network.rb +8 -14
  98. data/lib/ohai/plugins/solaris2/platform.rb +2 -3
  99. data/lib/ohai/plugins/solaris2/virtualization.rb +3 -6
  100. data/lib/ohai/plugins/ssh_host_key.rb +1 -1
  101. data/lib/ohai/plugins/uptime.rb +2 -2
  102. data/lib/ohai/plugins/virtualbox.rb +1 -1
  103. data/lib/ohai/plugins/vmware.rb +1 -1
  104. data/lib/ohai/plugins/windows/dmi.rb +2 -2
  105. data/lib/ohai/plugins/windows/drivers.rb +2 -2
  106. data/lib/ohai/plugins/windows/memory.rb +1 -1
  107. data/lib/ohai/plugins/windows/network.rb +3 -3
  108. data/lib/ohai/plugins/windows/platform.rb +1 -1
  109. data/lib/ohai/plugins/windows/system_enclosure.rb +1 -1
  110. data/lib/ohai/plugins/windows/virtualization.rb +2 -2
  111. data/lib/ohai/plugins/zpools.rb +1 -1
  112. data/lib/ohai/provides_map.rb +1 -1
  113. data/lib/ohai/runner.rb +2 -2
  114. data/lib/ohai/system.rb +2 -3
  115. data/lib/ohai/util/file_helper.rb +4 -37
  116. data/lib/ohai/util/ip_helper.rb +2 -2
  117. data/lib/ohai/util/win32.rb +1 -1
  118. data/lib/ohai/version.rb +3 -3
  119. data/ohai.gemspec +5 -7
  120. metadata +62 -73
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Matt Wrock (<matt@mattwrock.com>)
3
- # Copyright:: Copyright (c) 2016-2018 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");
@@ -29,10 +29,6 @@ Ohai.plugin(:Fips) do
29
29
  fips Mash.new
30
30
 
31
31
  require "openssl" unless defined?(OpenSSL)
32
- if defined?(OpenSSL.fips_mode) && OpenSSL.fips_mode && !$FIPS_TEST_MODE
33
- fips["kernel"] = { "enabled" => true }
34
- else
35
- fips["kernel"] = { "enabled" => false }
36
- end
32
+ fips["kernel"] = { "enabled" => OpenSSL::OPENSSL_FIPS }
37
33
  end
38
34
  end
@@ -20,10 +20,8 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
 
22
22
  collect_data(:freebsd) do
23
- so = shell_out("uname -s")
24
- platform so.stdout.split($/)[0].downcase
25
- so = shell_out("uname -r")
26
- platform_version so.stdout.split($/)[0]
23
+ platform shell_out("uname -s").stdout.split($/)[0].downcase
24
+ platform_version shell_out("uname -r").stdout.split($/)[0]
27
25
  platform_family "freebsd"
28
26
  end
29
27
  end
@@ -49,7 +49,7 @@ Ohai.plugin(:GCE) do
49
49
  # @return [Boolean] Are the manufacturer and model Google?
50
50
  def has_gce_system_info?
51
51
  if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
52
- require "wmi-lite/wmi"
52
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
53
53
  wmi = WmiLite::Wmi.new
54
54
  computer_system = wmi.first_of("Win32_ComputerSystem")
55
55
  if computer_system["Manufacturer"] =~ /^Google/ && computer_system["Model"] =~ /^Google/
@@ -6,7 +6,7 @@
6
6
  # Author:: Doug MacEachern (<dougm@vmware.com>)
7
7
  # Author:: James Gartrell (<jgartrel@gmail.com>)
8
8
  # Author:: Isa Farnik (<isa@chef.io>)
9
- # Copyright:: Copyright (c) 2008-2018, Chef Software Inc.
9
+ # Copyright:: Copyright (c) Chef Software Inc.
10
10
  # Copyright:: Copyright (c) 2009 Bryan McLellan
11
11
  # Copyright:: Copyright (c) 2009 Daniel DeLeo
12
12
  # Copyright:: Copyright (c) 2010 VMware, Inc.
@@ -26,9 +26,6 @@
26
26
  #
27
27
 
28
28
  Ohai.plugin(:Hostname) do
29
- require "socket" unless defined?(Socket)
30
- require "ipaddr"
31
-
32
29
  provides "domain", "hostname", "fqdn", "machinename"
33
30
 
34
31
  # hostname : short hostname
@@ -47,6 +44,9 @@ Ohai.plugin(:Hostname) do
47
44
  # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent)
48
45
  # this is ipv6-safe, works on ruby 1.8.7+
49
46
  def resolve_fqdn
47
+ require "socket" unless defined?(Socket)
48
+ require "ipaddr" unless defined?(IPAddr)
49
+
50
50
  hostname = from_cmd("hostname")
51
51
  addrinfo = Socket.getaddrinfo(hostname, nil).first
52
52
  iaddr = IPAddr.new(addrinfo[3])
@@ -161,7 +161,7 @@ Ohai.plugin(:Hostname) do
161
161
  end
162
162
 
163
163
  collect_data(:windows) do
164
- require "wmi-lite/wmi"
164
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
165
165
  require "socket" unless defined?(Socket)
166
166
 
167
167
  wmi = WmiLite::Wmi.new
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Caleb Tennis (<caleb.tennis@gmail.com>)
3
- # Copyright:: Copyright (c) 2012-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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Benjamin Black (<bb@chef.io>)
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");
@@ -4,7 +4,7 @@
4
4
  # Author:: Bryan McLellan (<btm@loftninjas.org>)
5
5
  # Author:: Claire McQuin (<claire@chef.io>)
6
6
  # Author:: James Gartrell (<jgartrel@gmail.com>)
7
- # Copyright:: Copyright (c) Chef Software, Inc.
7
+ # Copyright:: Copyright (c) Chef Software Inc.
8
8
  # Copyright:: Copyright (c) 2009 Bryan McLellan
9
9
  # License:: Apache License, Version 2.0
10
10
  #
@@ -42,7 +42,7 @@ Ohai.plugin(:Kernel) do
42
42
  # @return [Mash]
43
43
  def bsd_modules(path)
44
44
  modules = Mash.new
45
- so = shell_out((Ohai.abs_path(path)).to_s)
45
+ so = shell_out(Ohai.abs_path(path).to_s)
46
46
  so.stdout.lines do |line|
47
47
  # 1 7 0xc0400000 97f830 kernel
48
48
  if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
@@ -252,7 +252,7 @@ Ohai.plugin(:Kernel) do
252
252
 
253
253
  collect_data(:windows) do
254
254
  require "win32ole" unless defined?(WIN32OLE)
255
- require "wmi-lite/wmi"
255
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
256
256
 
257
257
  WIN32OLE.codepage = WIN32OLE::CP_UTF8
258
258
 
@@ -2,7 +2,7 @@
2
2
  # Cookbook Name:: apache2
3
3
  # Recipe:: default
4
4
  #
5
- # Copyright 2008-2016 Chef Software, Inc.
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
@@ -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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Benjamin Black (<bb@chef.io>)
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");
@@ -25,7 +25,7 @@ Ohai.plugin(:Linode) do
25
25
  # Returns true or false
26
26
  def has_linode_kernel?
27
27
  if ( kernel_data = kernel )
28
- kernel_data[:release].split("-").last =~ /linode/
28
+ kernel_data[:release].split("-").last.include?("linode")
29
29
  end
30
30
  end
31
31
 
@@ -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");
@@ -24,8 +24,7 @@ Ohai.plugin(:Hostnamectl) do
24
24
 
25
25
  hostnamectl_path = which("hostnamectl")
26
26
  if hostnamectl_path
27
- hostnamectl_cmd = shell_out(hostnamectl_path)
28
- hostnamectl_cmd.stdout.split("\n").each do |line|
27
+ shell_out(hostnamectl_path).stdout.split("\n").each do |line|
29
28
  key, val = line.split(":")
30
29
  hostnamectl[key.chomp.lstrip.tr(" ", "_").downcase] = val.chomp.lstrip
31
30
  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");
@@ -24,8 +24,7 @@ Ohai.plugin(:LSB) do
24
24
 
25
25
  if File.exist?("/usr/bin/lsb_release")
26
26
  # From package redhat-lsb on Fedora/Redhat, lsb-release on Debian/Ubuntu
27
- so = shell_out("lsb_release -a")
28
- so.stdout.lines do |line|
27
+ shell_out("lsb_release -a").stdout.lines do |line|
29
28
  case line
30
29
  when /^Distributor ID:\s+(.+)$/
31
30
  lsb[:id] = $1
@@ -24,7 +24,6 @@ Ohai.plugin(:Lspci) do
24
24
 
25
25
  collect_data(:linux) do
26
26
  devices = Mash.new
27
- lspci = shell_out("lspci -vnnmk")
28
27
 
29
28
  h = /[0-9a-fA-F]/ # any hex digit
30
29
  hh = /#{h}#{h}/ # any 2 hex digits
@@ -46,7 +45,7 @@ Ohai.plugin(:Lspci) do
46
45
  end
47
46
  end
48
47
 
49
- lspci.stdout.split("\n").each do |line|
48
+ shell_out("lspci -vnnmk").stdout.split("\n").each do |line|
50
49
  dev = line.scan(/^(.*):\s(.*)$/)[0]
51
50
  next if dev.nil?
52
51
 
@@ -20,12 +20,12 @@ Ohai.plugin(:Machineid) do
20
20
  provides "machine_id"
21
21
 
22
22
  collect_data(:linux) do
23
- mid = nil
24
-
25
23
  if ::File.exist?("/etc/machine-id")
26
24
  mid = ::File.read("/etc/machine-id").chomp
27
25
  elsif ::File.exist?("/var/lib/dbus/machine-id")
28
26
  mid = ::File.read("/var/lib/dbus/machine-id").chomp
27
+ else
28
+ mid = nil
29
29
  end
30
30
 
31
31
  if mid
@@ -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");
@@ -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");
@@ -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
@@ -478,7 +478,7 @@ Ohai.plugin(:Network) do
478
478
 
479
479
  # returns the macaddress for interface from a hash of interfaces (iface elsewhere in this file)
480
480
  def get_mac_for_interface(interfaces, interface)
481
- interfaces[interface][:addresses].select { |k, v| v["family"] == "lladdr" }.first.first unless interfaces[interface][:addresses].nil? || interfaces[interface][:flags].include?("NOARP")
481
+ interfaces[interface][:addresses].find { |k, v| v["family"] == "lladdr" }.first unless interfaces[interface][:addresses].nil? || interfaces[interface][:flags].include?("NOARP")
482
482
  end
483
483
 
484
484
  # returns the default route with the lowest metric (unspecified metric is 0)
@@ -516,8 +516,16 @@ Ohai.plugin(:Network) do
516
516
  # if the route destination is a default route, it's good
517
517
  return true if route[:destination] == "default"
518
518
 
519
+ return false if default_route[:via].nil?
520
+
521
+ dest_ipaddr = IPAddr.new(route[:destination])
522
+ default_route_via = IPAddr.new(default_route[:via])
523
+
524
+ # check if nexthop is the same address family
525
+ return false if dest_ipaddr.ipv4? != default_route_via.ipv4?
526
+
519
527
  # the default route has a gateway and the route matches the gateway
520
- !default_route[:via].nil? && IPAddress(route[:destination]).include?(IPAddress(default_route[:via]))
528
+ dest_ipaddr.include?(default_route_via)
521
529
  end
522
530
 
523
531
  # ipv4/ipv6 routes are different enough that having a single algorithm to select the favored route for both creates unnecessary complexity
@@ -569,7 +577,7 @@ Ohai.plugin(:Network) do
569
577
  # If the 'ip' binary is available, this plugin may set {ip,mac,ip6}address. The network plugin should not overwrite these.
570
578
  # The older code section below that relies on the deprecated net-tools, e.g. netstat and ifconfig, provides less functionality.
571
579
  collect_data(:linux) do
572
- require "ipaddr"
580
+ require "ipaddr" unless defined?(IPAddr)
573
581
 
574
582
  iface = Mash.new
575
583
  net_counters = Mash.new
@@ -638,7 +646,7 @@ Ohai.plugin(:Network) do
638
646
  logger.trace("Plugin Network: #{default_prefix}_interface set to #{default_route[:dev]}")
639
647
 
640
648
  # setting gateway to 0.0.0.0 or :: if the default route is a link level one
641
- 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")
642
650
  logger.trace("Plugin Network: #{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}")
643
651
 
644
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");
@@ -20,21 +20,6 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
  depends "lsb"
22
22
 
23
- # the platform mappings between the 'ID' field in /etc/os-release and the value
24
- # ohai uses. If you're adding a new platform here and you want to change the name
25
- # you'll want to add it here and then add a spec for the platform_id_remap method
26
- PLATFORM_MAPPINGS ||= {
27
- "rhel" => "redhat",
28
- "amzn" => "amazon",
29
- "ol" => "oracle",
30
- "sles" => "suse",
31
- "sles_sap" => "suse",
32
- "opensuse-leap" => "opensuseleap",
33
- "xenenterprise" => "xenserver",
34
- "cumulus-linux" => "cumulus",
35
- "archarm" => "arch",
36
- }.freeze
37
-
38
23
  # @deprecated
39
24
  def get_redhatish_platform(contents)
40
25
  contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
@@ -122,8 +107,20 @@ Ohai.plugin(:Platform) do
122
107
  # this catches the centos guest shell in the nexus switch which identifies itself as centos
123
108
  return "nexus_centos" if id == "centos" && os_release_file_is_cisco?
124
109
 
125
- # remap based on the hash of platforms
126
- PLATFORM_MAPPINGS[id] || id
110
+ # the platform mappings between the 'ID' field in /etc/os-release and the value
111
+ # ohai uses. If you're adding a new platform here and you want to change the name
112
+ # you'll want to add it here and then add a spec for the platform_id_remap method
113
+ {
114
+ "rhel" => "redhat",
115
+ "amzn" => "amazon",
116
+ "ol" => "oracle",
117
+ "sles" => "suse",
118
+ "sles_sap" => "suse",
119
+ "opensuse-leap" => "opensuseleap",
120
+ "xenenterprise" => "xenserver",
121
+ "cumulus-linux" => "cumulus",
122
+ "archarm" => "arch",
123
+ }[id] || id
127
124
  end
128
125
 
129
126
  #
@@ -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");
@@ -26,8 +26,7 @@ Ohai.plugin(:Network) do
26
26
  counters Mash.new unless counters
27
27
  counters[:network] ||= Mash.new
28
28
 
29
- so = shell_out("route -n get default")
30
- so.stdout.lines do |line|
29
+ shell_out("route -n get default").stdout.lines do |line|
31
30
  if line =~ /(\w+): ([\w\.]+)/
32
31
  case $1
33
32
  when "gateway"
@@ -39,9 +38,8 @@ Ohai.plugin(:Network) do
39
38
  end
40
39
 
41
40
  iface = Mash.new
42
- so = shell_out("#{Ohai.abs_path( "/sbin/ifconfig" )} -a")
43
41
  cint = nil
44
- so.stdout.lines do |line|
42
+ shell_out("#{Ohai.abs_path( "/sbin/ifconfig" )} -a").stdout.lines do |line|
45
43
  if line =~ /^([0-9a-zA-Z\.]+):\s+/
46
44
  cint = $1
47
45
  iface[cint] = Mash.new
@@ -85,8 +83,7 @@ Ohai.plugin(:Network) do
85
83
  end
86
84
  end
87
85
 
88
- so = shell_out("arp -an")
89
- so.stdout.lines do |line|
86
+ shell_out("arp -an").stdout.lines do |line|
90
87
  if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
91
88
  next unless iface[$3] # this should never happen
92
89
 
@@ -102,8 +99,7 @@ Ohai.plugin(:Network) do
102
99
  # Show the state of all network interfaces or a single interface
103
100
  # which have been auto-configured (interfaces statically configured
104
101
  # into a system, but not located at boot time are not shown).
105
- so = shell_out("netstat -idn")
106
- so.stdout.lines do |line|
102
+ shell_out("netstat -idn").stdout.lines do |line|
107
103
  # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll Drop
108
104
  # em0 1500 <Link> 00:11:25:2d:90:be 3719557 0 3369969 0 0 0
109
105
  # $1 $2 $3 $4 $5 $6 $7 $8
@@ -20,10 +20,8 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
 
22
22
  collect_data(:netbsd) do
23
- so = shell_out("uname -s")
24
- platform so.stdout.split($/)[0].downcase
25
- so = shell_out("uname -r")
26
- platform_version so.stdout.split($/)[0]
23
+ platform shell_out("uname -s").stdout.split($/)[0].downcase
24
+ platform_version shell_out("uname -r").stdout.split($/)[0]
27
25
  platform_family "netbsd"
28
26
  end
29
27
  end