ohai 8.13.0 → 8.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/ohai/common/dmi.rb +1 -1
- data/lib/ohai/config.rb +2 -2
- data/lib/ohai/dsl/plugin.rb +1 -1
- data/lib/ohai/loader.rb +1 -1
- data/lib/ohai/mixin/command.rb +18 -5
- data/lib/ohai/mixin/ec2_metadata.rb +1 -1
- data/lib/ohai/plugins/aix/os.rb +1 -1
- data/lib/ohai/plugins/c.rb +49 -67
- data/lib/ohai/plugins/darwin/memory.rb +1 -1
- data/lib/ohai/plugins/darwin/network.rb +3 -3
- data/lib/ohai/plugins/darwin/platform.rb +1 -1
- data/lib/ohai/plugins/darwin/system_profiler.rb +1 -1
- data/lib/ohai/plugins/digital_ocean.rb +1 -1
- data/lib/ohai/plugins/ec2.rb +42 -41
- data/lib/ohai/plugins/erlang.rb +1 -1
- data/lib/ohai/plugins/ip_scopes.rb +1 -1
- data/lib/ohai/plugins/kernel.rb +1 -1
- data/lib/ohai/plugins/linux/network.rb +2 -2
- data/lib/ohai/plugins/linux/platform.rb +6 -1
- data/lib/ohai/plugins/mono.rb +1 -1
- data/lib/ohai/plugins/network.rb +2 -2
- data/lib/ohai/plugins/packages.rb +59 -46
- data/lib/ohai/plugins/python.rb +2 -2
- data/lib/ohai/plugins/rackspace.rb +4 -4
- data/lib/ohai/plugins/sigar/network.rb +1 -1
- data/lib/ohai/plugins/sigar/network_route.rb +1 -1
- data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
- data/lib/ohai/plugins/solaris2/network.rb +25 -8
- data/lib/ohai/plugins/ssh_host_key.rb +1 -1
- data/lib/ohai/plugins/windows/network.rb +5 -5
- data/lib/ohai/provides_map.rb +2 -2
- data/lib/ohai/system.rb +1 -1
- data/lib/ohai/version.rb +1 -1
- data/spec/functional/loader_spec.rb +1 -1
- data/spec/unit/mixin/command_spec.rb +118 -0
- data/spec/unit/plugins/aix/os_spec.rb +6 -5
- data/spec/unit/plugins/c_spec.rb +169 -118
- data/spec/unit/plugins/digital_ocean_spec.rb +7 -7
- data/spec/unit/plugins/dmi_spec.rb +4 -4
- data/spec/unit/plugins/ec2_spec.rb +64 -69
- data/spec/unit/plugins/linode_spec.rb +6 -6
- data/spec/unit/plugins/linux/platform_spec.rb +7 -0
- data/spec/unit/plugins/linux/sessions_spec.rb +2 -2
- data/spec/unit/plugins/network_spec.rb +16 -16
- data/spec/unit/plugins/openstack_spec.rb +1 -1
- data/spec/unit/plugins/packages_spec.rb +165 -191
- data/spec/unit/plugins/rackspace_spec.rb +203 -130
- data/spec/unit/plugins/solaris2/filesystem.rb +2 -2
- data/spec/unit/plugins/solaris2/network_spec.rb +36 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 880a68c3c0a321e516f4ebd6fe4d8ea96dc4bd81
|
4
|
+
data.tar.gz: e6f7e6019d46c47e58cc642ba8104624bd5cfdd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79c39d1fc907eda3130f429f3ca5f0b7511e5448e83188ef6d59148b36d8e661bcc550a8e61eb194259c32fe42e015e5ef49236cde4636af68f1ad6d744326c1
|
7
|
+
data.tar.gz: 967a82e37972b3d947c81612d983e52124479c419d4a1161a9bf8e825d61b40fbeea720ff9658981daa2a228d87d04eec2048dc44ec64752c4b763dba795abd1
|
data/Gemfile
CHANGED
data/lib/ohai/common/dmi.rb
CHANGED
data/lib/ohai/config.rb
CHANGED
@@ -105,7 +105,7 @@ module Ohai
|
|
105
105
|
private
|
106
106
|
|
107
107
|
def self.option_deprecated(option)
|
108
|
-
<<-EOM.chomp!.
|
108
|
+
<<-EOM.chomp!.tr("\n", " ")
|
109
109
|
Ohai::Config[:#{option}] is set. Ohai::Config[:#{option}] is deprecated and will
|
110
110
|
be removed in future releases of ohai. Use ohai.#{option} in your configuration
|
111
111
|
file to configure :#{option} for ohai.
|
@@ -113,7 +113,7 @@ EOM
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def self.option_might_be_deprecated(option)
|
116
|
-
option_deprecated(option) + <<-EOM.chomp!.
|
116
|
+
option_deprecated(option) + <<-EOM.chomp!.tr("\n", " ")
|
117
117
|
If your configuration file is used with other applications which configure
|
118
118
|
:#{option}, and you have not configured Ohai::Config[:#{option}], you may
|
119
119
|
disregard this warning.
|
data/lib/ohai/dsl/plugin.rb
CHANGED
data/lib/ohai/loader.rb
CHANGED
@@ -173,7 +173,7 @@ For more information visit here: docs.chef.io/ohai_custom.html")
|
|
173
173
|
|
174
174
|
def load_v7_plugin_class(contents, plugin_path)
|
175
175
|
plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path)
|
176
|
-
unless plugin_class.kind_of?(Class)
|
176
|
+
unless plugin_class.kind_of?(Class) && plugin_class < Ohai::DSL::Plugin
|
177
177
|
raise Ohai::Exceptions::IllegalPluginDefinition, "Plugin file cannot contain any statements after the plugin definition"
|
178
178
|
end
|
179
179
|
plugin_class.sources << plugin_path
|
data/lib/ohai/mixin/command.rb
CHANGED
@@ -28,10 +28,23 @@ require "mixlib/shellout"
|
|
28
28
|
module Ohai
|
29
29
|
module Mixin
|
30
30
|
module Command
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
# DISCLAIMER: Logging only works in the context of a plugin!!
|
32
|
+
# accept a command and any of the mixlib-shellout options
|
33
|
+
def shell_out(cmd, **options)
|
34
|
+
# unless specified by the caller timeout after 30 seconds
|
35
|
+
options[:timeout] ||= 30
|
36
|
+
so = Mixlib::ShellOut.new(cmd, options)
|
37
|
+
begin
|
38
|
+
so.run_command
|
39
|
+
Ohai::Log.debug("Plugin #{self.name} ran '#{cmd}' and returned #{so.exitstatus}")
|
40
|
+
so
|
41
|
+
rescue Errno::ENOENT => e
|
42
|
+
Ohai::Log.debug("Plugin #{self.name} ran '#{cmd}' and failed #{e.inspect}")
|
43
|
+
raise Ohai::Exceptions::Exec, e
|
44
|
+
rescue Mixlib::ShellOut::CommandTimeout => e
|
45
|
+
Ohai::Log.debug("Plugin #{self.name} ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
|
46
|
+
raise Ohai::Exceptions::Exec, e
|
47
|
+
end
|
35
48
|
end
|
36
49
|
|
37
50
|
module_function :shell_out
|
@@ -70,7 +83,7 @@ module Ohai
|
|
70
83
|
|
71
84
|
args[:returns] ||= 0
|
72
85
|
args[:no_status_check] ||= false
|
73
|
-
if status.exitstatus != args[:returns]
|
86
|
+
if status.exitstatus != args[:returns] && (not args[:no_status_check])
|
74
87
|
raise Ohai::Exceptions::Exec, "#{args[:command_string]} returned #{status.exitstatus}, expected #{args[:returns]}"
|
75
88
|
else
|
76
89
|
Ohai::Log.debug("Ran #{args[:command_string]} (#{args[:command]}) returned #{status.exitstatus}")
|
data/lib/ohai/plugins/aix/os.rb
CHANGED
data/lib/ohai/plugins/c.rb
CHANGED
@@ -23,74 +23,64 @@ Ohai.plugin(:C) do
|
|
23
23
|
|
24
24
|
depends "languages"
|
25
25
|
|
26
|
+
def collect(cmd, &block)
|
27
|
+
so = shell_out(cmd)
|
28
|
+
yield(so) if so.exitstatus == 0
|
29
|
+
rescue Ohai::Exceptions::Exec
|
30
|
+
# ignore
|
31
|
+
end
|
32
|
+
|
26
33
|
collect_data do
|
27
34
|
c = Mash.new
|
28
35
|
|
29
36
|
#gcc
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
c[:gcc][:version] = output[2]
|
38
|
-
c[:gcc][:description] = description
|
39
|
-
end
|
37
|
+
collect("gcc -v") do |so|
|
38
|
+
description = so.stderr.split($/).last
|
39
|
+
output = description.split
|
40
|
+
if output.length >= 3
|
41
|
+
c[:gcc] = Mash.new
|
42
|
+
c[:gcc][:version] = output[2]
|
43
|
+
c[:gcc][:description] = description
|
40
44
|
end
|
41
|
-
rescue Errno::ENOENT
|
42
45
|
end
|
43
46
|
|
44
47
|
#glibc
|
45
48
|
["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc|
|
46
|
-
|
47
|
-
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
c[:glibc][:version] = $1
|
53
|
-
c[:glibc][:description] = description
|
54
|
-
end
|
55
|
-
break
|
49
|
+
collect( Ohai.abs_path( glibc )) do |so|
|
50
|
+
description = so.stdout.split($/).first
|
51
|
+
if description =~ /(\d+\.\d+\.?\d*)/
|
52
|
+
c[:glibc] = Mash.new
|
53
|
+
c[:glibc][:version] = $1
|
54
|
+
c[:glibc][:description] = description
|
56
55
|
end
|
57
|
-
|
58
|
-
end
|
56
|
+
end unless c[:glibc]
|
59
57
|
end
|
60
58
|
|
61
59
|
#ms cl
|
62
|
-
|
63
|
-
|
64
|
-
if
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
c[:cl][:version] = $1
|
69
|
-
c[:cl][:description] = description
|
70
|
-
end
|
60
|
+
collect("cl /?") do |so|
|
61
|
+
description = so.stderr.lines.first.chomp
|
62
|
+
if description =~ /Compiler Version ([\d\.]+)/
|
63
|
+
c[:cl] = Mash.new
|
64
|
+
c[:cl][:version] = $1
|
65
|
+
c[:cl][:description] = description
|
71
66
|
end
|
72
|
-
rescue Errno::ENOENT
|
73
67
|
end
|
74
68
|
|
75
69
|
#ms vs
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
c[:vs][:version] = $1.chop
|
84
|
-
c[:vs][:description] = description
|
85
|
-
end
|
70
|
+
collect("devenv.com /?") do |so|
|
71
|
+
lines = so.stdout.split($/)
|
72
|
+
description = lines[0].length == 0 ? lines[1] : lines[0]
|
73
|
+
if description =~ /Visual Studio Version ([\d\.]+)/
|
74
|
+
c[:vs] = Mash.new
|
75
|
+
c[:vs][:version] = $1.chop
|
76
|
+
c[:vs][:description] = description
|
86
77
|
end
|
87
|
-
rescue Errno::ENOENT
|
88
78
|
end
|
89
79
|
|
90
80
|
#ibm xlc
|
91
81
|
begin
|
92
82
|
so = shell_out("xlc -qversion")
|
93
|
-
if so.exitstatus == 0
|
83
|
+
if so.exitstatus == 0 || (so.exitstatus >> 8) == 249
|
94
84
|
description = so.stdout.split($/).first
|
95
85
|
if description =~ /V(\d+\.\d+)/
|
96
86
|
c[:xlc] = Mash.new
|
@@ -98,36 +88,28 @@ Ohai.plugin(:C) do
|
|
98
88
|
c[:xlc][:description] = description.strip
|
99
89
|
end
|
100
90
|
end
|
101
|
-
rescue
|
91
|
+
rescue Ohai::Exceptions::Exec
|
102
92
|
end
|
103
93
|
|
104
94
|
#sun pro
|
105
|
-
|
106
|
-
|
107
|
-
if so.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
c[:sunpro][:version] = output[3]
|
112
|
-
c[:sunpro][:description] = so.stderr.chomp
|
113
|
-
end
|
95
|
+
collect("cc -V -flags") do |so|
|
96
|
+
output = so.stderr.split
|
97
|
+
if so.stderr =~ /^cc: Sun C/ && output.size >= 4
|
98
|
+
c[:sunpro] = Mash.new
|
99
|
+
c[:sunpro][:version] = output[3]
|
100
|
+
c[:sunpro][:description] = so.stderr.chomp
|
114
101
|
end
|
115
|
-
rescue Errno::ENOENT
|
116
102
|
end
|
117
103
|
|
118
104
|
#hpux cc
|
119
|
-
|
120
|
-
|
121
|
-
if
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
c[:hpcc][:version] = output[1] if output.size >= 1
|
127
|
-
c[:hpcc][:description] = description.strip
|
128
|
-
end
|
105
|
+
collect("what /opt/ansic/bin/cc") do |so|
|
106
|
+
description = so.stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first
|
107
|
+
if description
|
108
|
+
output = description.split
|
109
|
+
c[:hpcc] = Mash.new
|
110
|
+
c[:hpcc][:version] = output[1] if output.size >= 1
|
111
|
+
c[:hpcc][:description] = description.strip
|
129
112
|
end
|
130
|
-
rescue Errno::ENOENT
|
131
113
|
end
|
132
114
|
|
133
115
|
languages[:c] = c if c.keys.length > 0
|
@@ -30,7 +30,7 @@ Ohai.plugin(:Memory) do
|
|
30
30
|
inactive = 0
|
31
31
|
vm_stat = shell_out("vm_stat").stdout
|
32
32
|
vm_stat_match = /page size of (\d+) bytes/.match(vm_stat)
|
33
|
-
page_size = if vm_stat_match
|
33
|
+
page_size = if vm_stat_match && vm_stat_match[1]
|
34
34
|
vm_stat_match[1].to_i
|
35
35
|
else
|
36
36
|
4096
|
@@ -61,8 +61,8 @@ Ohai.plugin(:Network) do
|
|
61
61
|
|
62
62
|
def scope_lookup(scope)
|
63
63
|
return "Node" if scope.eql?("::1")
|
64
|
-
return "Link" if scope
|
65
|
-
return "Site" if scope
|
64
|
+
return "Link" if scope =~ /^fe80\:/
|
65
|
+
return "Site" if scope =~ /^fec0\:/
|
66
66
|
"Global"
|
67
67
|
end
|
68
68
|
|
@@ -73,7 +73,7 @@ Ohai.plugin(:Network) do
|
|
73
73
|
def locate_interface(ifaces, ifname, mac)
|
74
74
|
return ifname unless ifaces[ifname].nil?
|
75
75
|
# oh well, time to go hunting!
|
76
|
-
return ifname.chop if ifname
|
76
|
+
return ifname.chop if ifname =~ /\*$/
|
77
77
|
ifaces.keys.each do |ifc|
|
78
78
|
ifaces[ifc][:addresses].keys.each do |addr|
|
79
79
|
return ifc if addr.eql? mac
|
data/lib/ohai/plugins/ec2.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# Author:: Tim Dysinger (<tim@dysinger.net>)
|
3
3
|
# Author:: Benjamin Black (<bb@chef.io>)
|
4
4
|
# Author:: Christopher Brown (<cb@chef.io>)
|
5
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
6
|
# Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
|
6
7
|
# License:: Apache License, Version 2.0
|
7
8
|
#
|
@@ -17,6 +18,12 @@
|
|
17
18
|
# See the License for the specific language governing permissions and
|
18
19
|
# limitations under the License.
|
19
20
|
|
21
|
+
# How we detect EC2 from easiest to hardest & least reliable
|
22
|
+
# 1. Ohai ec2 hint exists. This always works
|
23
|
+
# 2. Xen hypervisor UUID starts with 'ec2'. This catches Linux HVM & paravirt instances
|
24
|
+
# 3. DMI data mentions amazon. This catches HVM instances in a VPC
|
25
|
+
# 4. Kernel data mentioned Amazon. This catches Windows HVM & paravirt instances
|
26
|
+
|
20
27
|
require "ohai/mixin/ec2_metadata"
|
21
28
|
require "base64"
|
22
29
|
|
@@ -25,65 +32,59 @@ Ohai.plugin(:EC2) do
|
|
25
32
|
|
26
33
|
provides "ec2"
|
27
34
|
|
28
|
-
depends "network/interfaces"
|
29
35
|
depends "dmi"
|
30
|
-
|
31
|
-
# look for ec2metadata which is included on paravirt / hvm AMIs
|
32
|
-
def has_ec2metadata_bin?
|
33
|
-
if File.exist?("/usr/bin/ec2metadata")
|
34
|
-
Ohai::Log.debug("ec2 plugin: has_ec2metadata_bin? == true")
|
35
|
-
true
|
36
|
-
else
|
37
|
-
Ohai::Log.debug("ec2 plugin: has_ec2metadata_bin? == false")
|
38
|
-
false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# look for arp address that non-VPC hosts will have
|
43
|
-
def has_xen_mac?
|
44
|
-
network[:interfaces].values.each do |iface|
|
45
|
-
unless iface[:arp].nil?
|
46
|
-
if iface[:arp].value?("fe:ff:ff:ff:ff:ff")
|
47
|
-
# using MAC addresses from ARP is unreliable because they could time-out from the table
|
48
|
-
# fe:ff:ff:ff:ff:ff is actually a sign of Xen, not specifically EC2
|
49
|
-
deprecation_message <<-EOM
|
50
|
-
ec2 plugin: Detected EC2 by the presence of fe:ff:ff:ff:ff:ff in the ARP table. This method is unreliable and will be removed in a future version of ohai. Bootstrap using knife-ec2 or create "/etc/chef/ohai/hints/ec2.json" instead.
|
51
|
-
EOM
|
52
|
-
Ohai::Log.warn(deprecation_message)
|
53
|
-
Ohai::Log.debug("ec2 plugin: has_xen_mac? == true")
|
54
|
-
return true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
Ohai::Log.debug("ec2 plugin: has_xen_mac? == false")
|
59
|
-
false
|
60
|
-
end
|
36
|
+
depends "kernel"
|
61
37
|
|
62
38
|
# look for amazon string in dmi bios data
|
63
|
-
# this
|
39
|
+
# this gets us detection of HVM instances that are within a VPC
|
64
40
|
def has_ec2_dmi?
|
65
41
|
begin
|
66
42
|
# detect a version of '4.2.amazon'
|
67
43
|
if dmi[:bios][:all_records][0][:Version] =~ /amazon/
|
68
44
|
Ohai::Log.debug("ec2 plugin: has_ec2_dmi? == true")
|
69
|
-
true
|
45
|
+
return true
|
70
46
|
end
|
71
47
|
rescue NoMethodError
|
72
|
-
|
73
|
-
|
48
|
+
# dmi[:bios][:all_records][0][:Version] may not exist
|
49
|
+
end
|
50
|
+
Ohai::Log.debug("ec2 plugin: has_ec2_dmi? == false")
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
54
|
+
# looks for a xen UUID that starts with ec2
|
55
|
+
# this gets us detection of Linux HVM and Paravirt hosts
|
56
|
+
def has_ec2_xen_uuid?
|
57
|
+
if ::File.exist?("/sys/hypervisor/uuid")
|
58
|
+
if ::File.read("/sys/hypervisor/uuid") =~ /^ec2/
|
59
|
+
Ohai::Log.debug("ec2 plugin: has_ec2_xen_uuid? == true")
|
60
|
+
return true
|
61
|
+
end
|
74
62
|
end
|
63
|
+
Ohai::Log.debug("ec2 plugin: has_ec2_xen_uuid? == false")
|
64
|
+
return false
|
75
65
|
end
|
76
66
|
|
77
|
-
#
|
78
|
-
|
79
|
-
|
67
|
+
# looks for the Amazon.com Organization in Windows Kernel data
|
68
|
+
# this gets us detection of Windows systems
|
69
|
+
def has_amazon_org?
|
70
|
+
begin
|
71
|
+
# detect an Organization of 'Amazon.com'
|
72
|
+
if kernel[:os_info][:organization] =~ /Amazon/
|
73
|
+
Ohai::Log.debug("ec2 plugin: has_amazon_org? == true")
|
74
|
+
return true
|
75
|
+
end
|
76
|
+
rescue NoMethodError
|
77
|
+
# kernel[:os_info][:organization] may not exist
|
78
|
+
end
|
79
|
+
Ohai::Log.debug("ec2 plugin: has_amazon_org? == false")
|
80
|
+
return false
|
80
81
|
end
|
81
82
|
|
82
83
|
def looks_like_ec2?
|
83
84
|
return true if hint?("ec2")
|
84
85
|
|
85
86
|
# Even if it looks like EC2 try to connect first
|
86
|
-
if
|
87
|
+
if has_ec2_xen_uuid? || has_ec2_dmi? || has_amazon_org?
|
87
88
|
return true if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
|
88
89
|
end
|
89
90
|
end
|
@@ -100,7 +101,7 @@ EOM
|
|
100
101
|
next if k == "iam" && !hint?("iam")
|
101
102
|
ec2[k] = v
|
102
103
|
end
|
103
|
-
ec2[:userdata] =
|
104
|
+
ec2[:userdata] = fetch_userdata
|
104
105
|
# ASCII-8BIT is equivalent to BINARY in this case
|
105
106
|
if ec2[:userdata] && ec2[:userdata].encoding.to_s == "ASCII-8BIT"
|
106
107
|
Ohai::Log.debug("ec2 plugin: Binary UserData Found. Storing in base64")
|