ohai 8.10.0 → 8.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -2
- data/Rakefile +13 -4
- data/bin/ohai +3 -4
- data/lib/ohai.rb +4 -4
- data/lib/ohai/application.rb +7 -6
- data/lib/ohai/common/dmi.rb +56 -56
- data/lib/ohai/config.rb +12 -8
- data/lib/ohai/dsl.rb +3 -3
- data/lib/ohai/dsl/plugin.rb +5 -5
- data/lib/ohai/dsl/plugin/versionvi.rb +0 -1
- data/lib/ohai/dsl/plugin/versionvii.rb +1 -0
- data/lib/ohai/hints.rb +1 -1
- data/lib/ohai/loader.rb +7 -7
- data/lib/ohai/log.rb +1 -1
- data/lib/ohai/mash.rb +3 -2
- data/lib/ohai/mixin/command.rb +25 -23
- data/lib/ohai/mixin/dmi_decode.rb +10 -10
- data/lib/ohai/mixin/ec2_metadata.rb +40 -39
- data/lib/ohai/mixin/gce_metadata.rb +9 -9
- data/lib/ohai/mixin/network_constants.rb +1 -1
- data/lib/ohai/mixin/os.rb +3 -3
- data/lib/ohai/mixin/seconds_to_human.rb +0 -2
- data/lib/ohai/mixin/softlayer_metadata.rb +10 -10
- data/lib/ohai/mixin/string.rb +2 -2
- data/lib/ohai/plugin_config.rb +1 -1
- data/lib/ohai/plugins/aix/cpu.rb +2 -2
- data/lib/ohai/plugins/aix/filesystem.rb +2 -2
- data/lib/ohai/plugins/aix/memory.rb +2 -2
- data/lib/ohai/plugins/aix/network.rb +9 -10
- data/lib/ohai/plugins/aix/os.rb +2 -2
- data/lib/ohai/plugins/aix/uptime.rb +3 -3
- data/lib/ohai/plugins/aix/virtualization.rb +23 -23
- data/lib/ohai/plugins/azure.rb +32 -5
- data/lib/ohai/plugins/bsd/virtualization.rb +22 -22
- data/lib/ohai/plugins/c.rb +3 -3
- data/lib/ohai/plugins/chef.rb +1 -1
- data/lib/ohai/plugins/cloud.rb +59 -60
- data/lib/ohai/plugins/cloud_v2.rb +37 -39
- data/lib/ohai/plugins/darwin/cpu.rb +1 -1
- data/lib/ohai/plugins/darwin/filesystem2.rb +5 -5
- data/lib/ohai/plugins/darwin/memory.rb +5 -6
- data/lib/ohai/plugins/darwin/network.rb +7 -7
- data/lib/ohai/plugins/darwin/system_profiler.rb +32 -33
- data/lib/ohai/plugins/darwin/virtualization.rb +9 -9
- data/lib/ohai/plugins/digital_ocean.rb +16 -16
- data/lib/ohai/plugins/dmi.rb +6 -6
- data/lib/ohai/plugins/dragonflybsd/cpu.rb +2 -2
- data/lib/ohai/plugins/dragonflybsd/memory.rb +0 -1
- data/lib/ohai/plugins/dragonflybsd/network.rb +4 -4
- data/lib/ohai/plugins/dragonflybsd/os.rb +1 -1
- data/lib/ohai/plugins/ec2.rb +39 -15
- data/lib/ohai/plugins/elixir.rb +1 -1
- data/lib/ohai/plugins/erlang.rb +3 -3
- data/lib/ohai/plugins/eucalyptus.rb +16 -12
- data/lib/ohai/plugins/freebsd/cpu.rb +2 -2
- data/lib/ohai/plugins/freebsd/memory.rb +0 -1
- data/lib/ohai/plugins/freebsd/network.rb +4 -4
- data/lib/ohai/plugins/freebsd/os.rb +1 -1
- data/lib/ohai/plugins/gce.rb +6 -6
- data/lib/ohai/plugins/hostname.rb +7 -7
- data/lib/ohai/plugins/init_package.rb +1 -1
- data/lib/ohai/plugins/ip_scopes.rb +9 -9
- data/lib/ohai/plugins/java.rb +1 -1
- data/lib/ohai/plugins/joyent.rb +7 -7
- data/lib/ohai/plugins/kernel.rb +8 -8
- data/lib/ohai/plugins/linode.rb +7 -4
- data/lib/ohai/plugins/linux/cpu.rb +5 -5
- data/lib/ohai/plugins/linux/filesystem.rb +16 -16
- data/lib/ohai/plugins/linux/filesystem2.rb +15 -15
- data/lib/ohai/plugins/linux/mdadm.rb +3 -3
- data/lib/ohai/plugins/linux/network.rb +85 -51
- data/lib/ohai/plugins/linux/platform.rb +24 -24
- data/lib/ohai/plugins/linux/virtualization.rb +8 -8
- data/lib/ohai/plugins/mono.rb +1 -1
- data/lib/ohai/plugins/netbsd/cpu.rb +1 -1
- data/lib/ohai/plugins/netbsd/network.rb +2 -2
- data/lib/ohai/plugins/network.rb +11 -11
- data/lib/ohai/plugins/network_listeners.rb +30 -26
- data/lib/ohai/plugins/ohai.rb +3 -3
- data/lib/ohai/plugins/openbsd/cpu.rb +4 -4
- data/lib/ohai/plugins/openbsd/memory.rb +4 -4
- data/lib/ohai/plugins/openbsd/network.rb +3 -3
- data/lib/ohai/plugins/openstack.rb +12 -12
- data/lib/ohai/plugins/os.rb +2 -2
- data/lib/ohai/plugins/packages.rb +22 -22
- data/lib/ohai/plugins/passwd.rb +4 -4
- data/lib/ohai/plugins/powershell.rb +9 -9
- data/lib/ohai/plugins/ps.rb +2 -2
- data/lib/ohai/plugins/python.rb +1 -1
- data/lib/ohai/plugins/rackspace.rb +13 -13
- data/lib/ohai/plugins/root_group.rb +4 -4
- data/lib/ohai/plugins/ruby.rb +6 -6
- data/lib/ohai/plugins/rust.rb +1 -1
- data/lib/ohai/plugins/sigar/cpu.rb +1 -1
- data/lib/ohai/plugins/sigar/filesystem.rb +1 -1
- data/lib/ohai/plugins/sigar/network.rb +13 -13
- data/lib/ohai/plugins/sigar/network_route.rb +34 -29
- data/lib/ohai/plugins/softlayer.rb +8 -7
- data/lib/ohai/plugins/solaris2/cpu.rb +19 -19
- data/lib/ohai/plugins/solaris2/dmi.rb +63 -63
- data/lib/ohai/plugins/solaris2/filesystem.rb +13 -13
- data/lib/ohai/plugins/solaris2/memory.rb +2 -2
- data/lib/ohai/plugins/solaris2/network.rb +5 -5
- data/lib/ohai/plugins/solaris2/virtualization.rb +18 -18
- data/lib/ohai/plugins/solaris2/zpools.rb +1 -1
- data/lib/ohai/plugins/ssh_host_key.rb +2 -2
- data/lib/ohai/plugins/uptime.rb +4 -5
- data/lib/ohai/plugins/virtualbox.rb +2 -2
- data/lib/ohai/plugins/virtualization.rb +17 -17
- data/lib/ohai/plugins/vmware.rb +2 -2
- data/lib/ohai/plugins/windows/cpu.rb +14 -14
- data/lib/ohai/plugins/windows/drivers.rb +8 -8
- data/lib/ohai/plugins/windows/filesystem.rb +4 -4
- data/lib/ohai/plugins/windows/memory.rb +1 -1
- data/lib/ohai/plugins/windows/network.rb +10 -10
- data/lib/ohai/plugins/windows/platform.rb +1 -2
- data/lib/ohai/plugins/windows/virtualization.rb +17 -17
- data/lib/ohai/provides_map.rb +7 -7
- data/lib/ohai/runner.rb +3 -3
- data/lib/ohai/system.rb +21 -20
- data/lib/ohai/util/file_helper.rb +1 -2
- data/lib/ohai/util/ip_helper.rb +4 -4
- data/lib/ohai/util/win32.rb +5 -5
- data/lib/ohai/util/win32/group_helper.rb +4 -5
- data/lib/ohai/version.rb +1 -1
- data/ohai.gemspec +7 -5
- data/spec/functional/application_spec.rb +23 -23
- data/spec/functional/loader_spec.rb +1 -1
- data/spec/functional/plugins/powershell_spec.rb +13 -13
- data/spec/functional/plugins/root_group_spec.rb +5 -5
- data/spec/ohai_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -9
- data/spec/support/integration_helper.rb +7 -7
- data/spec/support/platform_helpers.rb +1 -1
- data/spec/unit/application_spec.rb +17 -17
- data/spec/unit/config_spec.rb +2 -2
- data/spec/unit/dsl/plugin_spec.rb +28 -28
- data/spec/unit/hints_spec.rb +3 -3
- data/spec/unit/loader_spec.rb +9 -9
- data/spec/unit/mixin/command_spec.rb +5 -5
- data/spec/unit/mixin/ec2_metadata_spec.rb +6 -6
- data/spec/unit/mixin/softlayer_metadata_spec.rb +19 -23
- data/spec/unit/plugin_config_spec.rb +5 -5
- data/spec/unit/plugins/abort_spec.rb +3 -3
- data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
- data/spec/unit/plugins/aix/filesystem_spec.rb +25 -25
- data/spec/unit/plugins/aix/hostname_spec.rb +1 -2
- data/spec/unit/plugins/aix/kernel_spec.rb +3 -3
- data/spec/unit/plugins/aix/memory_spec.rb +8 -8
- data/spec/unit/plugins/aix/network_spec.rb +38 -38
- data/spec/unit/plugins/aix/os_spec.rb +1 -2
- data/spec/unit/plugins/aix/platform_spec.rb +1 -1
- data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
- data/spec/unit/plugins/aix/virtualization_spec.rb +11 -11
- data/spec/unit/plugins/azure_spec.rb +118 -20
- data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
- data/spec/unit/plugins/bsd/virtualization_spec.rb +4 -4
- data/spec/unit/plugins/c_spec.rb +12 -12
- data/spec/unit/plugins/chef_spec.rb +2 -2
- data/spec/unit/plugins/cloud_spec.rb +37 -37
- data/spec/unit/plugins/cloud_v2_spec.rb +64 -65
- data/spec/unit/plugins/darwin/cpu_spec.rb +1 -2
- data/spec/unit/plugins/darwin/filesystem2_spec.rb +7 -7
- data/spec/unit/plugins/darwin/filesystem_spec.rb +5 -5
- data/spec/unit/plugins/darwin/hostname_spec.rb +1 -4
- data/spec/unit/plugins/darwin/kernel_spec.rb +6 -10
- data/spec/unit/plugins/darwin/memory_spec.rb +5 -5
- data/spec/unit/plugins/darwin/network_spec.rb +352 -353
- data/spec/unit/plugins/darwin/platform_spec.rb +1 -2
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +3 -3
- data/spec/unit/plugins/darwin/virtualization_spec.rb +6 -6
- data/spec/unit/plugins/digital_ocean_spec.rb +38 -37
- data/spec/unit/plugins/dmi_spec.rb +3 -3
- data/spec/unit/plugins/ec2_spec.rb +97 -88
- data/spec/unit/plugins/elixir_spec.rb +1 -2
- data/spec/unit/plugins/erlang_spec.rb +2 -2
- data/spec/unit/plugins/eucalyptus_spec.rb +19 -19
- data/spec/unit/plugins/fail_spec.rb +2 -2
- data/spec/unit/plugins/freebsd/cpu_spec.rb +14 -14
- data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -2
- data/spec/unit/plugins/freebsd/kernel_spec.rb +2 -3
- data/spec/unit/plugins/freebsd/os_spec.rb +4 -5
- data/spec/unit/plugins/freebsd/platform_spec.rb +1 -2
- data/spec/unit/plugins/gce_spec.rb +9 -9
- data/spec/unit/plugins/go_spec.rb +1 -1
- data/spec/unit/plugins/groovy_spec.rb +1 -2
- data/spec/unit/plugins/hostname_spec.rb +1 -2
- data/spec/unit/plugins/init_package_spec.rb +1 -1
- data/spec/unit/plugins/ip_scopes_spec.rb +38 -38
- data/spec/unit/plugins/java_spec.rb +52 -1
- data/spec/unit/plugins/joyent_spec.rb +9 -11
- data/spec/unit/plugins/kernel_spec.rb +11 -12
- data/spec/unit/plugins/linode_spec.rb +29 -29
- data/spec/unit/plugins/linux/block_device_spec.rb +21 -21
- data/spec/unit/plugins/linux/cpu_spec.rb +3 -3
- data/spec/unit/plugins/linux/filesystem2_spec.rb +7 -7
- data/spec/unit/plugins/linux/filesystem_spec.rb +85 -86
- data/spec/unit/plugins/linux/hostname_spec.rb +1 -3
- data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linux/lsb_spec.rb +1 -2
- data/spec/unit/plugins/linux/mdadm_spec.rb +4 -4
- data/spec/unit/plugins/linux/memory_spec.rb +29 -33
- data/spec/unit/plugins/linux/network_spec.rb +463 -245
- data/spec/unit/plugins/linux/platform_spec.rb +64 -65
- data/spec/unit/plugins/linux/uptime_spec.rb +1 -2
- data/spec/unit/plugins/linux/virtualization_spec.rb +42 -42
- data/spec/unit/plugins/lua_spec.rb +1 -2
- data/spec/unit/plugins/mono_spec.rb +1 -2
- data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -2
- data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -2
- data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/network_spec.rb +118 -118
- data/spec/unit/plugins/nodejs_spec.rb +1 -1
- data/spec/unit/plugins/ohai_spec.rb +1 -1
- data/spec/unit/plugins/ohai_time_spec.rb +1 -2
- data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -2
- data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -2
- data/spec/unit/plugins/openbsd/platform_spec.rb +1 -2
- data/spec/unit/plugins/openstack_spec.rb +35 -37
- data/spec/unit/plugins/os_spec.rb +7 -8
- data/spec/unit/plugins/packages_spec.rb +118 -118
- data/spec/unit/plugins/passwd_spec.rb +18 -18
- data/spec/unit/plugins/perl_spec.rb +1 -1
- data/spec/unit/plugins/php_spec.rb +4 -4
- data/spec/unit/plugins/platform_spec.rb +8 -9
- data/spec/unit/plugins/powershell_spec.rb +3 -3
- data/spec/unit/plugins/python_spec.rb +1 -1
- data/spec/unit/plugins/rackspace_spec.rb +66 -68
- data/spec/unit/plugins/root_group_spec.rb +26 -26
- data/spec/unit/plugins/ruby_spec.rb +14 -15
- data/spec/unit/plugins/rust_spec.rb +2 -2
- data/spec/unit/plugins/sigar/network_route_spec.rb +36 -36
- data/spec/unit/plugins/softlayer_spec.rb +10 -10
- data/spec/unit/plugins/solaris2/cpu_spec.rb +20 -21
- data/spec/unit/plugins/solaris2/dmi_spec.rb +5 -6
- data/spec/unit/plugins/solaris2/filesystem.rb +5 -5
- data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/kernel_spec.rb +3 -3
- data/spec/unit/plugins/solaris2/memory_spec.rb +5 -5
- data/spec/unit/plugins/solaris2/network_spec.rb +7 -8
- data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +3 -5
- data/spec/unit/plugins/solaris2/zpools_spec.rb +6 -6
- data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
- data/spec/unit/plugins/virtualbox_spec.rb +19 -19
- data/spec/unit/plugins/vmware_spec.rb +28 -28
- data/spec/unit/plugins/windows/cpu_spec.rb +46 -48
- data/spec/unit/plugins/windows/memory_spec.rb +5 -5
- data/spec/unit/plugins/windows/virtualization_spec.rb +163 -163
- data/spec/unit/provides_map_spec.rb +10 -10
- data/spec/unit/runner_spec.rb +10 -10
- data/spec/unit/system_spec.rb +19 -19
- data/spec/unit/util/file_helper_spec.rb +5 -6
- data/spec/unit/util/ip_helper_spec.rb +39 -39
- metadata +31 -4
data/lib/ohai/mixin/command.rb
CHANGED
@@ -16,14 +16,14 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
19
|
+
require "ohai/exception"
|
20
|
+
require "ohai/config"
|
21
|
+
require "ohai/log"
|
22
|
+
require "stringio"
|
23
|
+
require "tmpdir"
|
24
|
+
require "fcntl"
|
25
|
+
require "etc"
|
26
|
+
require "mixlib/shellout"
|
27
27
|
|
28
28
|
module Ohai
|
29
29
|
module Mixin
|
@@ -36,7 +36,8 @@ module Ohai
|
|
36
36
|
|
37
37
|
module_function :shell_out
|
38
38
|
|
39
|
-
def run_command(args={})
|
39
|
+
def run_command(args = {})
|
40
|
+
Ohai::Log.warn("Ohai::Mixin::Command run_command is deprecated and will be removed in Ohai 9.0.0")
|
40
41
|
if args.has_key?(:creates)
|
41
42
|
if File.exists?(args[:creates])
|
42
43
|
Ohai::Log.debug("Skipping #{args[:command]} - creates #{args[:creates]} exists.")
|
@@ -123,12 +124,13 @@ module Ohai
|
|
123
124
|
# The original appears in external/open4.rb in its unmodified form.
|
124
125
|
#
|
125
126
|
# Thanks Ara!
|
126
|
-
def popen4(cmd, args={}, &b)
|
127
|
+
def popen4(cmd, args = {}, &b)
|
128
|
+
Ohai::Log.warn("Ohai::Mixin::Command popen4 is deprecated and will be removed in Ohai 9.0.0")
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
130
|
+
# Disable garbage collection to work around possible bug in MRI
|
131
|
+
# Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select
|
132
|
+
# See OHAI-330 / CHEF-2916 / CHEF-1305
|
133
|
+
GC.disable
|
132
134
|
|
133
135
|
# Waitlast - this is magic.
|
134
136
|
#
|
@@ -189,7 +191,7 @@ module Ohai
|
|
189
191
|
Process.uid = args[:user]
|
190
192
|
end
|
191
193
|
|
192
|
-
args[:environment].each do |key,value|
|
194
|
+
args[:environment].each do |key, value|
|
193
195
|
ENV[key] = value
|
194
196
|
end
|
195
197
|
|
@@ -204,19 +206,19 @@ module Ohai
|
|
204
206
|
else
|
205
207
|
exec(cmd)
|
206
208
|
end
|
207
|
-
raise
|
209
|
+
raise "forty-two"
|
208
210
|
rescue Exception => e
|
209
211
|
Marshal.dump(e, ps.last)
|
210
212
|
ps.last.flush
|
211
213
|
end
|
212
|
-
ps.last.close unless
|
214
|
+
ps.last.close unless ps.last.closed?
|
213
215
|
exit!
|
214
216
|
}
|
215
217
|
ensure
|
216
218
|
$VERBOSE = verbose
|
217
219
|
end
|
218
220
|
|
219
|
-
[pw.first, pr.last, pe.last, ps.last].each{|fd| fd.close}
|
221
|
+
[pw.first, pr.last, pe.last, ps.last].each { |fd| fd.close }
|
220
222
|
|
221
223
|
begin
|
222
224
|
e = Marshal.load ps.first
|
@@ -325,15 +327,15 @@ module Ohai
|
|
325
327
|
# have encoding methods.
|
326
328
|
if "".respond_to?(:force_encoding) && defined?(Encoding)
|
327
329
|
o.string.force_encoding(Encoding.default_external)
|
328
|
-
o.string.encode!(
|
330
|
+
o.string.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")
|
329
331
|
e.string.force_encoding(Encoding.default_external)
|
330
|
-
e.string.encode!(
|
332
|
+
e.string.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")
|
331
333
|
end
|
332
334
|
b[cid, pi[0], o, e]
|
333
335
|
results.last
|
334
336
|
end
|
335
337
|
ensure
|
336
|
-
pi.each{|fd| fd.close unless fd.closed?}
|
338
|
+
pi.each { |fd| fd.close unless fd.closed? }
|
337
339
|
end
|
338
340
|
else
|
339
341
|
[cid, pw.last, pr.first, pe.first]
|
@@ -341,8 +343,8 @@ module Ohai
|
|
341
343
|
rescue Errno::ENOENT
|
342
344
|
raise Ohai::Exceptions::Exec, "command #{cmd} doesn't exist or is not in the PATH"
|
343
345
|
ensure
|
344
|
-
|
345
|
-
|
346
|
+
# we disabled GC entering
|
347
|
+
GC.enable
|
346
348
|
end
|
347
349
|
|
348
350
|
module_function :popen4
|
@@ -22,24 +22,24 @@ module ::Ohai::Mixin::DmiDecode
|
|
22
22
|
case line
|
23
23
|
when /Manufacturer: Microsoft/
|
24
24
|
if dmi_data =~ /Product Name: Virtual Machine/
|
25
|
-
if dmi_data =~ /Version: (
|
26
|
-
return
|
27
|
-
elsif dmi_data =~ /Version: (
|
28
|
-
return
|
25
|
+
if dmi_data =~ /Version: (7.0|Hyper-V)/
|
26
|
+
return "hyperv"
|
27
|
+
elsif dmi_data =~ /Version: (VS2005R2|6.0)/
|
28
|
+
return "virtualpc"
|
29
29
|
elsif dmi_data =~ /Version: 5.0/
|
30
|
-
return
|
30
|
+
return "virtualserver"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
when /Manufacturer: VMware/
|
34
|
-
return
|
34
|
+
return "vmware"
|
35
35
|
when /Manufacturer: Xen/
|
36
|
-
return
|
36
|
+
return "xen"
|
37
37
|
when /Product Name: VirtualBox/
|
38
|
-
return
|
38
|
+
return "vbox"
|
39
39
|
when /Product Name: OpenStack/
|
40
|
-
return
|
40
|
+
return "openstack"
|
41
41
|
when /Manufacturer: QEMU|Product Name: (KVM|RHEV)/
|
42
|
-
return
|
42
|
+
return "kvm"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
return nil
|
@@ -17,8 +17,8 @@
|
|
17
17
|
# See the License for the specific language governing permissions and
|
18
18
|
# limitations under the License.
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
20
|
+
require "net/http"
|
21
|
+
require "socket"
|
22
22
|
|
23
23
|
module Ohai
|
24
24
|
module Mixin
|
@@ -41,14 +41,15 @@ module Ohai
|
|
41
41
|
module Ec2Metadata
|
42
42
|
|
43
43
|
EC2_METADATA_ADDR = "169.254.169.254" unless defined?(EC2_METADATA_ADDR)
|
44
|
-
EC2_SUPPORTED_VERSIONS = %w
|
45
|
-
2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12
|
44
|
+
EC2_SUPPORTED_VERSIONS = %w{ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15
|
45
|
+
2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12
|
46
|
+
2014-11-05 2014-02-25 }
|
46
47
|
|
47
|
-
EC2_ARRAY_VALUES = %w
|
48
|
-
EC2_ARRAY_DIR = %w
|
49
|
-
EC2_JSON_DIR = %w
|
48
|
+
EC2_ARRAY_VALUES = %w{security-groups}
|
49
|
+
EC2_ARRAY_DIR = %w{network/interfaces/macs}
|
50
|
+
EC2_JSON_DIR = %w{iam}
|
50
51
|
|
51
|
-
def can_metadata_connect?(addr, port, timeout=2)
|
52
|
+
def can_metadata_connect?(addr, port, timeout = 2)
|
52
53
|
t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
|
53
54
|
saddr = Socket.pack_sockaddr_in(port, addr)
|
54
55
|
connected = false
|
@@ -56,7 +57,7 @@ module Ohai
|
|
56
57
|
begin
|
57
58
|
t.connect_nonblock(saddr)
|
58
59
|
rescue Errno::EINPROGRESS
|
59
|
-
r,w,e = IO
|
60
|
+
r, w, e = IO.select(nil, [t], nil, timeout)
|
60
61
|
if !w.nil?
|
61
62
|
connected = true
|
62
63
|
else
|
@@ -70,27 +71,27 @@ module Ohai
|
|
70
71
|
end
|
71
72
|
rescue SystemCallError
|
72
73
|
end
|
73
|
-
Ohai::Log.debug("can_metadata_connect? == #{connected}")
|
74
|
+
Ohai::Log.debug("ec2 metadata mixin: can_metadata_connect? == #{connected}")
|
74
75
|
connected
|
75
76
|
end
|
76
77
|
|
77
78
|
def best_api_version
|
78
79
|
response = http_client.get("/")
|
79
|
-
if response.code ==
|
80
|
-
Ohai::Log.debug("Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
|
80
|
+
if response.code == "404"
|
81
|
+
Ohai::Log.debug("ec2 metadata mixin: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
|
81
82
|
return "latest"
|
82
|
-
elsif response.code !=
|
83
|
+
elsif response.code != "200"
|
83
84
|
raise "Unable to determine EC2 metadata version (returned #{response.code} response)"
|
84
85
|
end
|
85
86
|
# Note: Sorting the list of versions may have unintended consequences in
|
86
87
|
# non-EC2 environments. It appears to be safe in EC2 as of 2013-04-12.
|
87
88
|
versions = response.body.split("\n")
|
88
89
|
versions = response.body.split("\n").sort
|
89
|
-
until
|
90
|
+
until versions.empty? || EC2_SUPPORTED_VERSIONS.include?(versions.last)
|
90
91
|
pv = versions.pop
|
91
|
-
Ohai::Log.debug("EC2 shows unsupported metadata version: #{pv}") unless pv ==
|
92
|
+
Ohai::Log.debug("ec2 metadata mixin: EC2 shows unsupported metadata version: #{pv}") unless pv == "latest"
|
92
93
|
end
|
93
|
-
Ohai::Log.debug("EC2 metadata version: #{versions.last}")
|
94
|
+
Ohai::Log.debug("ec2 metadata mixin: EC2 metadata version: #{versions.last}")
|
94
95
|
if versions.empty?
|
95
96
|
raise "Unable to determine EC2 metadata version (no supported entries found)"
|
96
97
|
end
|
@@ -98,7 +99,7 @@ module Ohai
|
|
98
99
|
end
|
99
100
|
|
100
101
|
def http_client
|
101
|
-
Net::HTTP.start(EC2_METADATA_ADDR).tap {|h| h.read_timeout =
|
102
|
+
Net::HTTP.start(EC2_METADATA_ADDR).tap { |h| h.read_timeout = 30 }
|
102
103
|
end
|
103
104
|
|
104
105
|
# Get metadata for a given path and API version
|
@@ -112,26 +113,26 @@ module Ohai
|
|
112
113
|
path = "/#{api_version}/meta-data/#{id}"
|
113
114
|
response = http_client.get(path)
|
114
115
|
case response.code
|
115
|
-
when
|
116
|
+
when "200"
|
116
117
|
response.body
|
117
|
-
when
|
118
|
-
Ohai::Log.debug("Encountered 404 response retreiving EC2 metadata path: #{path} ; continuing.")
|
118
|
+
when "404"
|
119
|
+
Ohai::Log.debug("ec2 metadata mixin: Encountered 404 response retreiving EC2 metadata path: #{path} ; continuing.")
|
119
120
|
nil
|
120
121
|
else
|
121
122
|
raise "Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)"
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
125
|
-
def fetch_metadata(id=
|
126
|
+
def fetch_metadata(id = "", api_version = nil)
|
126
127
|
api_version ||= best_api_version
|
127
|
-
return
|
128
|
+
return {} if api_version.nil?
|
128
129
|
|
129
|
-
metadata =
|
130
|
+
metadata = {}
|
130
131
|
retrieved_metadata = metadata_get(id, api_version)
|
131
132
|
if retrieved_metadata
|
132
133
|
retrieved_metadata.split("\n").each do |o|
|
133
134
|
key = expand_path("#{id}#{o}")
|
134
|
-
if key[-1..-1] !=
|
135
|
+
if key[-1..-1] != "/"
|
135
136
|
metadata[metadata_key(key)] =
|
136
137
|
if EC2_ARRAY_VALUES.include? key
|
137
138
|
retr_meta = metadata_get(key, api_version)
|
@@ -139,7 +140,7 @@ module Ohai
|
|
139
140
|
else
|
140
141
|
metadata_get(key, api_version)
|
141
142
|
end
|
142
|
-
elsif not key.eql?(id) and not key.eql?(
|
143
|
+
elsif not key.eql?(id) and not key.eql?("/")
|
143
144
|
name = key[0..-2]
|
144
145
|
sym = metadata_key(name)
|
145
146
|
if EC2_ARRAY_DIR.include?(name)
|
@@ -147,7 +148,7 @@ module Ohai
|
|
147
148
|
elsif EC2_JSON_DIR.include?(name)
|
148
149
|
metadata[sym] = fetch_json_dir_metadata(key, api_version)
|
149
150
|
else
|
150
|
-
fetch_metadata(key, api_version).each{|k,v| metadata[k] = v}
|
151
|
+
fetch_metadata(key, api_version).each { |k, v| metadata[k] = v }
|
151
152
|
end
|
152
153
|
end
|
153
154
|
end
|
@@ -161,10 +162,10 @@ module Ohai
|
|
161
162
|
if retrieved_metadata
|
162
163
|
retrieved_metadata.split("\n").each do |o|
|
163
164
|
key = expand_path(o)
|
164
|
-
if key[-1..-1] !=
|
165
|
+
if key[-1..-1] != "/"
|
165
166
|
retr_meta = metadata_get("#{id}#{key}", api_version)
|
166
|
-
metadata[metadata_key(key)] = retr_meta ? retr_meta :
|
167
|
-
elsif not key.eql?(
|
167
|
+
metadata[metadata_key(key)] = retr_meta ? retr_meta : ""
|
168
|
+
elsif not key.eql?("/")
|
168
169
|
metadata[key[0..-2]] = fetch_dir_metadata("#{id}#{key}", api_version)
|
169
170
|
end
|
170
171
|
end
|
@@ -173,18 +174,18 @@ module Ohai
|
|
173
174
|
end
|
174
175
|
|
175
176
|
def fetch_json_dir_metadata(id, api_version)
|
176
|
-
metadata =
|
177
|
+
metadata = {}
|
177
178
|
retrieved_metadata = metadata_get(id, api_version)
|
178
179
|
if retrieved_metadata
|
179
180
|
retrieved_metadata.split("\n").each do |o|
|
180
181
|
key = expand_path(o)
|
181
|
-
if key[-1..-1] !=
|
182
|
+
if key[-1..-1] != "/"
|
182
183
|
retr_meta = metadata_get("#{id}#{key}", api_version)
|
183
|
-
data = retr_meta ? retr_meta :
|
184
|
+
data = retr_meta ? retr_meta : ""
|
184
185
|
json = StringIO.new(data)
|
185
186
|
parser = FFI_Yajl::Parser.new
|
186
187
|
metadata[metadata_key(key)] = parser.parse(json)
|
187
|
-
elsif not key.eql?(
|
188
|
+
elsif not key.eql?("/")
|
188
189
|
metadata[key[0..-2]] = fetch_json_dir_metadata("#{id}#{key}", api_version)
|
189
190
|
end
|
190
191
|
end
|
@@ -192,7 +193,7 @@ module Ohai
|
|
192
193
|
end
|
193
194
|
end
|
194
195
|
|
195
|
-
def fetch_userdata
|
196
|
+
def fetch_userdata
|
196
197
|
api_version = best_api_version
|
197
198
|
return nil if api_version.nil?
|
198
199
|
response = http_client.get("/#{api_version}/user-data/")
|
@@ -202,15 +203,15 @@ module Ohai
|
|
202
203
|
private
|
203
204
|
|
204
205
|
def expand_path(file_name)
|
205
|
-
path = file_name.gsub(/\=.*$/,
|
206
|
+
path = file_name.gsub(/\=.*$/, "/")
|
206
207
|
# ignore "./" and "../"
|
207
|
-
path.gsub(%r{/\.\.?(?:/|$)},
|
208
|
-
sub(%r{^\.\.?(?:/|$)},
|
209
|
-
sub(%r{^$},
|
208
|
+
path.gsub(%r{/\.\.?(?:/|$)}, "/").
|
209
|
+
sub(%r{^\.\.?(?:/|$)}, "").
|
210
|
+
sub(%r{^$}, "/")
|
210
211
|
end
|
211
212
|
|
212
213
|
def metadata_key(key)
|
213
|
-
key.gsub(/\-|\//,
|
214
|
+
key.gsub(/\-|\//, "_")
|
214
215
|
end
|
215
216
|
|
216
217
|
end
|
@@ -14,8 +14,8 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
require
|
18
|
-
require
|
17
|
+
require "net/http"
|
18
|
+
require "socket"
|
19
19
|
|
20
20
|
module Ohai
|
21
21
|
module Mixin
|
@@ -25,7 +25,7 @@ module Ohai
|
|
25
25
|
GCE_METADATA_ADDR = "metadata.google.internal." unless defined?(GCE_METADATA_ADDR)
|
26
26
|
GCE_METADATA_URL = "/computeMetadata/v1beta1/?recursive=true" unless defined?(GCE_METADATA_URL)
|
27
27
|
|
28
|
-
def can_metadata_connect?(addr, port, timeout=2)
|
28
|
+
def can_metadata_connect?(addr, port, timeout = 2)
|
29
29
|
t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
|
30
30
|
saddr = Socket.pack_sockaddr_in(port, addr)
|
31
31
|
connected = false
|
@@ -33,7 +33,7 @@ module Ohai
|
|
33
33
|
begin
|
34
34
|
t.connect_nonblock(saddr)
|
35
35
|
rescue Errno::EINPROGRESS
|
36
|
-
r,w,e = IO
|
36
|
+
r, w, e = IO.select(nil, [t], nil, timeout)
|
37
37
|
if !w.nil?
|
38
38
|
connected = true
|
39
39
|
else
|
@@ -52,10 +52,10 @@ module Ohai
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def http_client
|
55
|
-
Net::HTTP.start(GCE_METADATA_ADDR).tap {|h| h.read_timeout = 6}
|
55
|
+
Net::HTTP.start(GCE_METADATA_ADDR).tap { |h| h.read_timeout = 6 }
|
56
56
|
end
|
57
57
|
|
58
|
-
def fetch_metadata(id=
|
58
|
+
def fetch_metadata(id = "")
|
59
59
|
uri = "#{GCE_METADATA_URL}/#{id}"
|
60
60
|
response = http_client.get(uri)
|
61
61
|
return nil unless response.code == "200"
|
@@ -64,8 +64,8 @@ module Ohai
|
|
64
64
|
data = StringIO.new(response.body)
|
65
65
|
parser = FFI_Yajl::Parser.new
|
66
66
|
parser.parse(data)
|
67
|
-
elsif
|
68
|
-
temp={}
|
67
|
+
elsif has_trailing_slash?(id) or (id == "")
|
68
|
+
temp = {}
|
69
69
|
response.body.split("\n").each do |sub_attr|
|
70
70
|
temp[sanitize_key(sub_attr)] = fetch_metadata("#{id}#{sub_attr}")
|
71
71
|
end
|
@@ -95,7 +95,7 @@ module Ohai
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def sanitize_key(key)
|
98
|
-
key.gsub(/\-|\//,
|
98
|
+
key.gsub(/\-|\//, "_")
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/lib/ohai/mixin/os.rb
CHANGED
@@ -17,14 +17,14 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "rbconfig"
|
21
21
|
|
22
22
|
module Ohai
|
23
23
|
module Mixin
|
24
24
|
module OS
|
25
25
|
|
26
26
|
def collect_os
|
27
|
-
case ::RbConfig::CONFIG[
|
27
|
+
case ::RbConfig::CONFIG["host_os"]
|
28
28
|
when /aix(.+)$/
|
29
29
|
return "aix"
|
30
30
|
when /darwin(.+)$/
|
@@ -51,7 +51,7 @@ module Ohai
|
|
51
51
|
# subsystems.
|
52
52
|
return "windows"
|
53
53
|
else
|
54
|
-
return ::RbConfig::CONFIG[
|
54
|
+
return ::RbConfig::CONFIG["host_os"]
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -17,20 +17,20 @@
|
|
17
17
|
# See the License for the specific language governing permissions and
|
18
18
|
# limitations under the License.
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
20
|
+
require "net/https"
|
21
|
+
require "uri"
|
22
22
|
|
23
23
|
# http://sldn.softlayer.com/reference/services/SoftLayer_Resource_Metadata
|
24
24
|
module ::Ohai::Mixin::SoftlayerMetadata
|
25
|
-
SOFTLAYER_API_QUERY_URL =
|
25
|
+
SOFTLAYER_API_QUERY_URL = "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata" unless defined?(SOFTLAYER_API_QUERY_URL)
|
26
26
|
|
27
27
|
def fetch_metadata
|
28
|
-
metadata
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
metadata = {
|
29
|
+
"public_fqdn" => fetch_metadata_item("getFullyQualifiedDomainName.txt"),
|
30
|
+
"local_ipv4" => fetch_metadata_item("getPrimaryBackendIpAddress.txt"),
|
31
|
+
"public_ipv4" => fetch_metadata_item("getPrimaryIpAddress.txt"),
|
32
|
+
"region" => fetch_metadata_item("getDatacenter.txt"),
|
33
|
+
"instance_id" => fetch_metadata_item("getId.txt"),
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
@@ -51,7 +51,7 @@ module ::Ohai::Mixin::SoftlayerMetadata
|
|
51
51
|
net.use_ssl = true
|
52
52
|
net.ca_file = ca_file_location
|
53
53
|
res = net.get(u.request_uri)
|
54
|
-
if res.code.to_i.between?(200,299)
|
54
|
+
if res.code.to_i.between?(200, 299)
|
55
55
|
res.body
|
56
56
|
else
|
57
57
|
::Ohai::Log.error("Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})")
|