ohai 6.24.2 → 7.0.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohai.rb +1 -1
- data/lib/ohai/application.rb +5 -12
- data/lib/ohai/common/dmi.rb +126 -0
- data/lib/ohai/config.rb +9 -9
- data/lib/ohai/{plugins/darwin/hostname.rb → dsl.rb} +7 -7
- data/lib/ohai/dsl/plugin.rb +186 -0
- data/lib/ohai/dsl/plugin/versionvi.rb +62 -0
- data/lib/ohai/dsl/plugin/versionvii.rb +106 -0
- data/lib/ohai/exception.rb +11 -2
- data/lib/ohai/hints.rb +48 -0
- data/lib/ohai/loader.rb +205 -0
- data/lib/ohai/mixin/command.rb +14 -18
- data/lib/ohai/mixin/constant_helper.rb +53 -0
- data/lib/ohai/mixin/gce_metadata.rb +0 -2
- data/lib/ohai/{plugins/freebsd/uptime.rb → mixin/network_constants.rb} +15 -13
- data/lib/ohai/mixin/os.rb +59 -0
- data/lib/ohai/mixin/seconds_to_human.rb +48 -0
- data/lib/ohai/plugins/aix/cpu.rb +26 -22
- data/lib/ohai/plugins/aix/filesystem.rb +47 -48
- data/lib/ohai/plugins/aix/kernel.rb +11 -7
- data/lib/ohai/plugins/aix/memory.rb +8 -4
- data/lib/ohai/plugins/aix/network.rb +73 -82
- data/lib/ohai/plugins/aix/platform.rb +9 -6
- data/lib/ohai/plugins/aix/uptime.rb +14 -12
- data/lib/ohai/plugins/azure.rb +33 -11
- data/lib/ohai/plugins/c.rb +103 -78
- data/lib/ohai/plugins/chef.rb +20 -8
- data/lib/ohai/plugins/cloud.rb +234 -230
- data/lib/ohai/plugins/command.rb +6 -2
- data/lib/ohai/plugins/darwin/cpu.rb +10 -4
- data/lib/ohai/plugins/darwin/filesystem.rb +32 -32
- data/lib/ohai/plugins/darwin/network.rb +157 -154
- data/lib/ohai/plugins/darwin/platform.rb +18 -16
- data/lib/ohai/plugins/darwin/system_profiler.rb +49 -46
- data/lib/ohai/plugins/dmi.rb +102 -102
- data/lib/ohai/plugins/ec2.rb +30 -28
- data/lib/ohai/plugins/erlang.rb +19 -16
- data/lib/ohai/plugins/eucalyptus.rb +37 -36
- data/lib/ohai/plugins/freebsd/cpu.rb +34 -29
- data/lib/ohai/plugins/freebsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/freebsd/memory.rb +35 -25
- data/lib/ohai/plugins/freebsd/network.rb +94 -89
- data/lib/ohai/plugins/freebsd/platform.rb +10 -4
- data/lib/ohai/plugins/freebsd/virtualization.rb +62 -61
- data/lib/ohai/plugins/gce.rb +30 -36
- data/lib/ohai/plugins/groovy.rb +14 -11
- data/lib/ohai/plugins/hostname.rb +132 -10
- data/lib/ohai/plugins/ip_scopes.rb +31 -16
- data/lib/ohai/plugins/java.rb +45 -21
- data/lib/ohai/plugins/kernel.rb +186 -19
- data/lib/ohai/plugins/keys.rb +6 -2
- data/lib/ohai/plugins/languages.rb +6 -2
- data/lib/ohai/plugins/linode.rb +38 -30
- data/lib/ohai/plugins/linux/block_device.rb +19 -15
- data/lib/ohai/plugins/linux/cpu.rb +42 -38
- data/lib/ohai/plugins/linux/filesystem.rb +70 -130
- data/lib/ohai/plugins/linux/lsb.rb +35 -35
- data/lib/ohai/plugins/linux/memory.rb +65 -61
- data/lib/ohai/plugins/linux/network.rb +343 -362
- data/lib/ohai/plugins/linux/platform.rb +90 -88
- data/lib/ohai/plugins/linux/virtualization.rb +95 -90
- data/lib/ohai/plugins/lua.rb +14 -10
- data/lib/ohai/plugins/mono.rb +17 -13
- data/lib/ohai/plugins/netbsd/cpu.rb +25 -23
- data/lib/ohai/plugins/netbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/netbsd/memory.rb +59 -59
- data/lib/ohai/plugins/netbsd/network.rb +92 -88
- data/lib/ohai/plugins/netbsd/platform.rb +10 -3
- data/lib/ohai/plugins/netbsd/virtualization.rb +41 -38
- data/lib/ohai/plugins/network.rb +131 -130
- data/lib/ohai/plugins/network_listeners.rb +26 -22
- data/lib/ohai/plugins/nodejs.rb +14 -10
- data/lib/ohai/plugins/ohai.rb +11 -6
- data/lib/ohai/plugins/ohai_time.rb +6 -2
- data/lib/ohai/plugins/openbsd/cpu.rb +20 -15
- data/lib/ohai/plugins/openbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/openbsd/memory.rb +59 -59
- data/lib/ohai/plugins/openbsd/network.rb +92 -88
- data/lib/ohai/plugins/openbsd/platform.rb +10 -4
- data/lib/ohai/plugins/openbsd/virtualization.rb +41 -39
- data/lib/ohai/plugins/openstack.rb +23 -21
- data/lib/ohai/plugins/os.rb +8 -32
- data/lib/ohai/plugins/passwd.rb +27 -22
- data/lib/ohai/plugins/perl.rb +21 -16
- data/lib/ohai/plugins/php.rb +15 -12
- data/lib/ohai/plugins/platform.rb +9 -9
- data/lib/ohai/plugins/{linux/kernel.rb → ps.rb} +13 -12
- data/lib/ohai/plugins/python.rb +16 -12
- data/lib/ohai/plugins/rackspace.rb +82 -77
- data/lib/ohai/plugins/root_group.rb +13 -9
- data/lib/ohai/plugins/ruby.rb +50 -48
- data/lib/ohai/plugins/sigar/cpu.rb +21 -17
- data/lib/ohai/plugins/sigar/filesystem.rb +26 -23
- data/lib/ohai/plugins/sigar/memory.rb +17 -14
- data/lib/ohai/plugins/sigar/network.rb +133 -67
- data/lib/ohai/plugins/sigar/network_route.rb +33 -28
- data/lib/ohai/plugins/sigar/platform.rb +10 -6
- data/lib/ohai/plugins/solaris2/cpu.rb +41 -33
- data/lib/ohai/plugins/solaris2/dmi.rb +146 -146
- data/lib/ohai/plugins/solaris2/filesystem.rb +74 -77
- data/lib/ohai/plugins/{aix/hostname.rb → solaris2/memory.rb} +7 -4
- data/lib/ohai/plugins/solaris2/network.rb +91 -86
- data/lib/ohai/plugins/solaris2/platform.rb +40 -36
- data/lib/ohai/plugins/solaris2/virtualization.rb +54 -59
- data/lib/ohai/plugins/solaris2/zpools.rb +38 -38
- data/lib/ohai/plugins/ssh_host_key.rb +49 -45
- data/lib/ohai/plugins/uptime.rb +87 -25
- data/lib/ohai/plugins/virtualization.rb +59 -55
- data/lib/ohai/plugins/windows/cpu.rb +44 -40
- data/lib/ohai/plugins/windows/filesystem.rb +28 -22
- data/lib/ohai/plugins/windows/network.rb +88 -79
- data/lib/ohai/plugins/windows/platform.rb +10 -3
- data/lib/ohai/provides_map.rb +184 -0
- data/lib/ohai/runner.rb +109 -0
- data/lib/ohai/system.rb +103 -184
- data/lib/ohai/version.rb +4 -3
- data/spec/data/plugins/___lib64___libc.so.6.output +135 -0
- data/spec/data/plugins/___lib___libc.so.6.output +135 -0
- data/spec/data/plugins/cc.output +135 -0
- data/spec/data/plugins/cl.output +135 -0
- data/spec/data/plugins/devenv.com.output +135 -0
- data/spec/data/plugins/env.output +71 -0
- data/spec/data/plugins/erl.output +144 -0
- data/spec/data/plugins/gcc.output +135 -0
- data/spec/data/plugins/groovy.output +159 -0
- data/spec/data/plugins/java.output +143 -0
- data/spec/data/plugins/lua.output +143 -0
- data/spec/data/plugins/messages.rb +8 -0
- data/spec/data/plugins/node.output +143 -0
- data/spec/data/plugins/perl.output +143 -0
- data/spec/data/plugins/php.output +143 -0
- data/spec/data/plugins/python.output +143 -0
- data/spec/data/plugins/uname.output +71 -0
- data/spec/data/plugins/v6message.rb +2 -0
- data/spec/data/plugins/v7message.rb +7 -0
- data/spec/data/plugins/what.output +135 -0
- data/spec/data/plugins/xlc.output +135 -0
- data/spec/spec_helper.rb +52 -18
- data/spec/support/integration_helper.rb +44 -0
- data/spec/unit/dsl/plugin_spec.rb +298 -0
- data/spec/unit/hints_spec.rb +65 -0
- data/spec/unit/loader_spec.rb +226 -0
- data/spec/unit/mixin/ec2_metadata_spec.rb +9 -9
- data/spec/unit/plugins/aix/cpu_spec.rb +17 -18
- data/spec/unit/plugins/aix/filesystem_spec.rb +20 -18
- data/spec/unit/plugins/aix/hostname_spec.rb +8 -4
- data/spec/unit/plugins/aix/kernel_spec.rb +13 -12
- data/spec/unit/plugins/aix/network_spec.rb +66 -45
- data/spec/unit/plugins/aix/platform_spec.rb +11 -10
- data/spec/unit/plugins/aix/uptime_spec.rb +7 -8
- data/spec/unit/plugins/azure_spec.rb +20 -21
- data/spec/unit/plugins/c_spec.rb +88 -87
- data/spec/unit/plugins/chef_spec.rb +5 -6
- data/spec/unit/plugins/cloud_spec.rb +81 -82
- data/spec/unit/plugins/darwin/cpu_spec.rb +8 -9
- data/spec/unit/plugins/darwin/hostname_spec.rb +23 -11
- data/spec/unit/plugins/darwin/kernel_spec.rb +39 -16
- data/spec/unit/plugins/darwin/network_spec.rb +375 -378
- data/spec/unit/plugins/darwin/platform_spec.rb +23 -50
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +7 -8
- data/spec/unit/plugins/dmi_spec.rb +7 -12
- data/spec/unit/plugins/ec2_spec.rb +70 -59
- data/spec/unit/plugins/erlang_spec.rb +18 -20
- data/spec/unit/plugins/eucalyptus_spec.rb +37 -33
- data/spec/unit/plugins/fail_spec.rb +276 -23
- data/spec/unit/plugins/freebsd/hostname_spec.rb +11 -9
- data/spec/unit/plugins/freebsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/freebsd/platform_spec.rb +9 -10
- data/spec/unit/plugins/freebsd/virtualization_spec.rb +32 -32
- data/spec/unit/plugins/gce_spec.rb +19 -25
- data/spec/unit/plugins/groovy_spec.rb +10 -16
- data/spec/unit/plugins/hostname_spec.rb +45 -20
- data/spec/unit/plugins/ip_scopes_spec.rb +97 -0
- data/spec/unit/plugins/java_spec.rb +145 -99
- data/spec/unit/plugins/kernel_spec.rb +51 -15
- data/spec/unit/plugins/linode_spec.rb +31 -29
- data/spec/unit/plugins/linux/cpu_spec.rb +42 -43
- data/spec/unit/plugins/linux/filesystem_spec.rb +143 -324
- data/spec/unit/plugins/linux/hostname_spec.rb +16 -23
- data/spec/unit/plugins/linux/kernel_spec.rb +22 -8
- data/spec/unit/plugins/linux/lsb_spec.rb +54 -56
- data/spec/unit/plugins/linux/network_spec.rb +196 -238
- data/spec/unit/plugins/linux/platform_spec.rb +186 -205
- data/spec/unit/plugins/linux/uptime_spec.rb +13 -25
- data/spec/unit/plugins/linux/virtualization_spec.rb +149 -129
- data/spec/unit/plugins/lua_spec.rb +12 -15
- data/spec/unit/plugins/mono_spec.rb +10 -15
- data/spec/unit/plugins/netbsd/hostname_spec.rb +17 -7
- data/spec/unit/plugins/netbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/netbsd/platform_spec.rb +8 -10
- data/spec/unit/plugins/network_spec.rb +358 -235
- data/spec/unit/plugins/nodejs_spec.rb +13 -15
- data/spec/unit/plugins/ohai_spec.rb +3 -4
- data/spec/unit/plugins/ohai_time_spec.rb +8 -9
- data/spec/unit/plugins/openbsd/hostname_spec.rb +21 -11
- data/spec/unit/plugins/openbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/openbsd/platform_spec.rb +6 -12
- data/spec/unit/plugins/openstack_spec.rb +214 -0
- data/spec/unit/plugins/os_spec.rb +13 -16
- data/spec/unit/plugins/passwd_spec.rb +12 -13
- data/spec/unit/plugins/perl_spec.rb +20 -44
- data/spec/unit/plugins/php_spec.rb +20 -15
- data/spec/unit/plugins/platform_spec.rb +24 -29
- data/spec/unit/plugins/python_spec.rb +13 -17
- data/spec/unit/plugins/rackspace_spec.rb +90 -57
- data/spec/unit/plugins/root_group_spec.rb +17 -19
- data/spec/unit/plugins/ruby_spec.rb +15 -16
- data/spec/unit/plugins/sigar/network_route_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/cpu_spec.rb +82 -0
- data/spec/unit/plugins/solaris2/hostname_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/kernel_spec.rb +11 -15
- data/{lib/ohai/plugins/openbsd/uptime.rb → spec/unit/plugins/solaris2/memory_spec.rb} +10 -12
- data/spec/unit/plugins/solaris2/network_spec.rb +44 -20
- data/spec/unit/plugins/solaris2/platform_spec.rb +13 -22
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +37 -45
- data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -15
- data/spec/unit/provides_map_spec.rb +208 -0
- data/spec/unit/runner_spec.rb +488 -0
- data/spec/unit/system_spec.rb +639 -104
- metadata +151 -87
- checksums.yaml +0 -7
- data/lib/ohai/mixin/from_file.rb +0 -36
- data/lib/ohai/plugins/aix/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/kernel.rb +0 -37
- data/lib/ohai/plugins/darwin/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/uptime.rb +0 -32
- data/lib/ohai/plugins/dmi_common.rb +0 -121
- data/lib/ohai/plugins/freebsd/hostname.rb +0 -22
- data/lib/ohai/plugins/freebsd/kernel.rb +0 -37
- data/lib/ohai/plugins/freebsd/ps.rb +0 -24
- data/lib/ohai/plugins/hpux/cpu.rb +0 -19
- data/lib/ohai/plugins/hpux/filesystem.rb +0 -19
- data/lib/ohai/plugins/hpux/hostname.rb +0 -19
- data/lib/ohai/plugins/hpux/memory.rb +0 -19
- data/lib/ohai/plugins/hpux/network.rb +0 -19
- data/lib/ohai/plugins/hpux/platform.rb +0 -19
- data/lib/ohai/plugins/hpux/ps.rb +0 -23
- data/lib/ohai/plugins/hpux/uptime.rb +0 -19
- data/lib/ohai/plugins/linux/hostname.rb +0 -40
- data/lib/ohai/plugins/linux/ps.rb +0 -23
- data/lib/ohai/plugins/linux/uptime.rb +0 -28
- data/lib/ohai/plugins/netbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/netbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/netbsd/ps.rb +0 -24
- data/lib/ohai/plugins/netbsd/uptime.rb +0 -31
- data/lib/ohai/plugins/openbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/openbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/openbsd/ps.rb +0 -24
- data/lib/ohai/plugins/sigar/hostname.rb +0 -28
- data/lib/ohai/plugins/sigar/uptime.rb +0 -27
- data/lib/ohai/plugins/solaris2/hostname.rb +0 -34
- data/lib/ohai/plugins/solaris2/kernel.rb +0 -40
- data/lib/ohai/plugins/solaris2/ps.rb +0 -23
- data/lib/ohai/plugins/solaris2/uptime.rb +0 -36
- data/lib/ohai/plugins/windows/hostname.rb +0 -33
- data/lib/ohai/plugins/windows/kernel.rb +0 -58
- data/lib/ohai/plugins/windows/kernel_devices.rb +0 -39
- data/lib/ohai/plugins/windows/uptime.rb +0 -23
- data/spec/unit/mixin/from_file_spec.rb +0 -53
data/lib/ohai.rb
CHANGED
data/lib/ohai/application.rb
CHANGED
@@ -27,11 +27,6 @@ class Ohai::Application
|
|
27
27
|
:long => "--directory DIRECTORY",
|
28
28
|
:description => "A directory to add to the Ohai search path"
|
29
29
|
|
30
|
-
option :file,
|
31
|
-
:short => "-f FILE",
|
32
|
-
:long => "--file FILE",
|
33
|
-
:description => "A file to run Ohai against"
|
34
|
-
|
35
30
|
option :log_level,
|
36
31
|
:short => "-l LEVEL",
|
37
32
|
:long => "--log_level LEVEL",
|
@@ -56,7 +51,7 @@ class Ohai::Application
|
|
56
51
|
option :version,
|
57
52
|
:short => "-v",
|
58
53
|
:long => "--version",
|
59
|
-
:description => "Show
|
54
|
+
:description => "Show Ohai version",
|
60
55
|
:boolean => true,
|
61
56
|
:proc => lambda {|v| puts "Ohai: #{::Ohai::VERSION}"},
|
62
57
|
:exit => 0
|
@@ -77,6 +72,7 @@ class Ohai::Application
|
|
77
72
|
|
78
73
|
def configure_ohai
|
79
74
|
@attributes = parse_options
|
75
|
+
@attributes = nil if @attributes.empty?
|
80
76
|
|
81
77
|
Ohai::Config.merge!(config)
|
82
78
|
if Ohai::Config[:directory]
|
@@ -91,12 +87,9 @@ class Ohai::Application
|
|
91
87
|
|
92
88
|
def run_application
|
93
89
|
ohai = Ohai::System.new
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
ohai.all_plugins
|
98
|
-
end
|
99
|
-
if @attributes.length > 0
|
90
|
+
ohai.all_plugins(@attributes)
|
91
|
+
|
92
|
+
if @attributes
|
100
93
|
@attributes.each do |a|
|
101
94
|
puts ohai.attributes_print(a)
|
102
95
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Kurt Yoder (ktyopscode@yoderhome.com)
|
3
|
+
# Copyright:: Copyright (c) 2010 Kurt Yoder
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module Ohai
|
20
|
+
module Common
|
21
|
+
module DMI
|
22
|
+
# List of IDs and what they translate to
|
23
|
+
# from 'man 8 dmidecode'
|
24
|
+
# all-lowercase, all non-alphanumeric converted to '_'
|
25
|
+
# 128-255 are 'oem_data_[id]'
|
26
|
+
# Everything else is 'unknown'
|
27
|
+
IdToDescription = {
|
28
|
+
0 => 'bios',
|
29
|
+
1 => 'system',
|
30
|
+
2 => 'base_board',
|
31
|
+
3 => 'chassis',
|
32
|
+
4 => 'processor',
|
33
|
+
5 => 'memory_controller',
|
34
|
+
6 => 'memory_module',
|
35
|
+
7 => 'cache',
|
36
|
+
8 => 'port_connector',
|
37
|
+
9 => 'system_slots',
|
38
|
+
10 => 'on_board_devices',
|
39
|
+
11 => 'oem_strings',
|
40
|
+
12 => 'system_configuration_options',
|
41
|
+
13 => 'bios_language',
|
42
|
+
14 => 'group_associations',
|
43
|
+
15 => 'system_event_log',
|
44
|
+
16 => 'physical_memory_array',
|
45
|
+
17 => 'memory_device',
|
46
|
+
18 => '32_bit_memory_error',
|
47
|
+
19 => 'memory_array_mapped_address',
|
48
|
+
20 => 'memory_device_mapped_address',
|
49
|
+
21 => 'built_in_pointing_device',
|
50
|
+
22 => 'portable_battery',
|
51
|
+
23 => 'system_reset',
|
52
|
+
24 => 'hardware_security',
|
53
|
+
25 => 'system_power_controls',
|
54
|
+
26 => 'voltage_probe',
|
55
|
+
27 => 'cooling_device',
|
56
|
+
28 => 'temperature_probe',
|
57
|
+
29 => 'electrical_current_probe',
|
58
|
+
30 => 'out_of_band_remote_access',
|
59
|
+
31 => 'boot_integrity_services',
|
60
|
+
32 => 'system_boot',
|
61
|
+
33 => '64_bit_memory_error',
|
62
|
+
34 => 'management_device',
|
63
|
+
35 => 'management_device_component',
|
64
|
+
36 => 'management_device_threshold_data',
|
65
|
+
37 => 'memory_channel',
|
66
|
+
38 => 'ipmi_device',
|
67
|
+
39 => 'power_supply',
|
68
|
+
126 => 'disabled_entries',
|
69
|
+
127 => 'end_of_table_marker',
|
70
|
+
}
|
71
|
+
|
72
|
+
# list of IDs to collect, otherwise we generate pages of hashes about cache chip size and whatnot
|
73
|
+
# See OHAI-260. When we can give the user a choice, this will be a default.
|
74
|
+
IdToCapture = [ 0, 1, 2, 3, 4, 6, 11 ]
|
75
|
+
|
76
|
+
# look up DMI ID
|
77
|
+
def id_lookup(id)
|
78
|
+
begin
|
79
|
+
id = id.to_i
|
80
|
+
if (id >= 128) and (id <= 255)
|
81
|
+
id = "oem_data_#{id}"
|
82
|
+
elsif DMI::IdToDescription.has_key?(id)
|
83
|
+
id = DMI::IdToDescription[id]
|
84
|
+
else
|
85
|
+
Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
|
86
|
+
id = 'unknown'
|
87
|
+
end
|
88
|
+
rescue
|
89
|
+
Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
|
90
|
+
id
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# create simplified convenience access keys for each record type
|
95
|
+
# for single occurrences of one type, copy to top level all fields and values
|
96
|
+
# for multiple occurrences of same type, copy to top level all fields and values that are common to all records
|
97
|
+
def convenience_keys(dmi)
|
98
|
+
dmi.each{ |type, records|
|
99
|
+
in_common = Mash.new
|
100
|
+
next unless records.class.to_s == 'Mash'
|
101
|
+
next unless records.has_key?('all_records')
|
102
|
+
records[:all_records].each{ |record|
|
103
|
+
record.each{ |field, value|
|
104
|
+
next if value.class.to_s == 'Mash'
|
105
|
+
next if field.to_s == 'application_identifier'
|
106
|
+
next if field.to_s == 'size'
|
107
|
+
next if field.to_s == 'record_id'
|
108
|
+
translated = field.downcase.gsub(/[^a-z0-9]/, '_')
|
109
|
+
if in_common.has_key?(translated)
|
110
|
+
in_common[translated] = nil unless in_common[translated] == value
|
111
|
+
else
|
112
|
+
in_common[translated] = value
|
113
|
+
end
|
114
|
+
}
|
115
|
+
}
|
116
|
+
in_common.each{ |field, value|
|
117
|
+
next if value == nil
|
118
|
+
dmi[type][field] = value
|
119
|
+
}
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
module_function :id_lookup, :convenience_keys
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/ohai/config.rb
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -21,7 +21,7 @@ require 'mixlib/config'
|
|
21
21
|
module Ohai
|
22
22
|
class Config
|
23
23
|
extend Mixlib::Config
|
24
|
-
|
24
|
+
|
25
25
|
# from chef/config.rb, should maybe be moved to mixlib-config?
|
26
26
|
def self.platform_specific_path(path)
|
27
27
|
if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
@@ -32,12 +32,12 @@ module Ohai
|
|
32
32
|
end
|
33
33
|
path
|
34
34
|
end
|
35
|
-
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
|
37
|
+
default :log_level, :info
|
38
|
+
default :log_location, STDERR
|
39
|
+
default :plugin_path, [ File.expand_path(File.join(File.dirname(__FILE__), 'plugins'))]
|
40
|
+
default :disabled_plugins, []
|
41
|
+
default(:hints_path) { [ platform_specific_path('/etc/chef/ohai/hints') ] }
|
42
42
|
end
|
43
43
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Author:: Serdar Sutay (<serdar@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -11,12 +11,12 @@
|
|
11
11
|
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
+
# implied.
|
15
16
|
# See the License for the specific language governing permissions and
|
16
17
|
# limitations under the License.
|
17
18
|
#
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
fqdn from("hostname")
|
20
|
+
require 'ohai/dsl/plugin'
|
21
|
+
require 'ohai/dsl/plugin/versionvi'
|
22
|
+
require 'ohai/dsl/plugin/versionvii'
|
@@ -0,0 +1,186 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Claire McQuin (<claire@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008, 2013 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ohai/mixin/os'
|
22
|
+
require 'ohai/mixin/command'
|
23
|
+
require 'ohai/mixin/seconds_to_human'
|
24
|
+
require 'ohai/hints'
|
25
|
+
|
26
|
+
module Ohai
|
27
|
+
|
28
|
+
# For plugin namespacing
|
29
|
+
module NamedPlugin
|
30
|
+
def self.valid_name?(name)
|
31
|
+
name.is_a?(Symbol) && name.to_s.match(/^[^A-Z]|_/).nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
# dealing with ruby 1.8
|
35
|
+
if Module.method(:const_defined?).arity == 1
|
36
|
+
def self.strict_const_defined?(const)
|
37
|
+
const_defined?(const)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
def self.strict_const_defined?(const)
|
41
|
+
const_defined?(const, false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.plugin(name, &block)
|
47
|
+
raise Ohai::Exceptions::InvalidPluginName, "#{name} is not a valid plugin name. A valid plugin name is a symbol which begins with a capital letter and contains no underscores" unless NamedPlugin.valid_name?(name)
|
48
|
+
|
49
|
+
plugin = nil
|
50
|
+
|
51
|
+
if NamedPlugin.strict_const_defined?(name)
|
52
|
+
plugin = NamedPlugin.const_get(name)
|
53
|
+
plugin.class_eval(&block)
|
54
|
+
else
|
55
|
+
klass = Class.new(DSL::Plugin::VersionVII, &block)
|
56
|
+
plugin = NamedPlugin.const_set(name, klass)
|
57
|
+
end
|
58
|
+
|
59
|
+
plugin
|
60
|
+
end
|
61
|
+
|
62
|
+
# Cross platform /dev/null to support testability
|
63
|
+
def self.dev_null
|
64
|
+
if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
65
|
+
"NUL"
|
66
|
+
else
|
67
|
+
"/dev/null"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Extracted abs_path to support testability:
|
72
|
+
# This method gets overridden at test time, to force the shell to check
|
73
|
+
# ohai/spec/unit/path/original/absolute/path/to/exe
|
74
|
+
def self.abs_path( abs_path )
|
75
|
+
abs_path
|
76
|
+
end
|
77
|
+
|
78
|
+
module DSL
|
79
|
+
class Plugin
|
80
|
+
|
81
|
+
include Ohai::Mixin::OS
|
82
|
+
include Ohai::Mixin::Command
|
83
|
+
include Ohai::Mixin::SecondsToHuman
|
84
|
+
|
85
|
+
attr_reader :data
|
86
|
+
|
87
|
+
def initialize(data)
|
88
|
+
@data = data
|
89
|
+
@has_run = false
|
90
|
+
end
|
91
|
+
|
92
|
+
def run
|
93
|
+
@has_run = true
|
94
|
+
run_plugin
|
95
|
+
end
|
96
|
+
|
97
|
+
def has_run?
|
98
|
+
@has_run
|
99
|
+
end
|
100
|
+
|
101
|
+
def reset!
|
102
|
+
@has_run = false
|
103
|
+
end
|
104
|
+
|
105
|
+
def [](key)
|
106
|
+
@data[key]
|
107
|
+
end
|
108
|
+
|
109
|
+
def []=(key, value)
|
110
|
+
@data[key] = value
|
111
|
+
end
|
112
|
+
|
113
|
+
def each(&block)
|
114
|
+
@data.each do |key, value|
|
115
|
+
block.call(key, value)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def attribute?(name)
|
120
|
+
@data.has_key?(name)
|
121
|
+
end
|
122
|
+
|
123
|
+
def set(name, *value)
|
124
|
+
set_attribute(name, *value)
|
125
|
+
end
|
126
|
+
|
127
|
+
def from(cmd)
|
128
|
+
status, stdout, stderr = run_command(:command => cmd)
|
129
|
+
return "" if stdout.nil? || stdout.empty?
|
130
|
+
stdout.strip
|
131
|
+
end
|
132
|
+
|
133
|
+
# Set the value equal to the stdout of the command, plus
|
134
|
+
# run through a regex - the first piece of match data is\
|
135
|
+
# the value.
|
136
|
+
def from_with_regex(cmd, *regex_list)
|
137
|
+
regex_list.flatten.each do |regex|
|
138
|
+
status, stdout, stderr = run_command(:command => cmd)
|
139
|
+
return "" if stdout.nil? || stdout.empty?
|
140
|
+
stdout.chomp!.strip
|
141
|
+
md = stdout.match(regex)
|
142
|
+
return md[1]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def set_attribute(name, *values)
|
147
|
+
@data[name] = Array18(*values)
|
148
|
+
@data[name]
|
149
|
+
end
|
150
|
+
|
151
|
+
def get_attribute(name)
|
152
|
+
@data[name]
|
153
|
+
end
|
154
|
+
|
155
|
+
def hint?(name)
|
156
|
+
Ohai::Hints.hint?(name)
|
157
|
+
end
|
158
|
+
|
159
|
+
# emulates the old plugin loading behavior
|
160
|
+
def safe_run
|
161
|
+
begin
|
162
|
+
self.run
|
163
|
+
rescue Ohai::Exceptions::Error => e
|
164
|
+
raise e
|
165
|
+
rescue => e
|
166
|
+
Ohai::Log.debug("Plugin #{self.name} threw #{e.inspect}")
|
167
|
+
e.backtrace.each { |line| Ohai::Log.debug( line )}
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def method_missing(name, *args)
|
172
|
+
return get_attribute(name) if args.length == 0
|
173
|
+
|
174
|
+
set_attribute(name, *args)
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
def Array18(*args)
|
180
|
+
return nil if args.empty?
|
181
|
+
return args.first if args.length == 1
|
182
|
+
return *args
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Serdar Sutay (<serdar@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
+
# implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
module Ohai
|
21
|
+
module DSL
|
22
|
+
class Plugin
|
23
|
+
class VersionVI < Plugin
|
24
|
+
attr_reader :version
|
25
|
+
attr_reader :source
|
26
|
+
|
27
|
+
def initialize(controller, plugin_path, plugin_dir_path)
|
28
|
+
super(controller.data)
|
29
|
+
@controller = controller
|
30
|
+
@version = :version6
|
31
|
+
@source = plugin_path
|
32
|
+
@plugin_dir_path = plugin_dir_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def name
|
36
|
+
# Ohai V6 doesn't have any name specification for plugins.
|
37
|
+
# So we are using the partial path to infer the name of the plugin
|
38
|
+
partial_path = Pathname.new(@source).relative_path_from(Pathname.new(@plugin_dir_path)).to_s
|
39
|
+
partial_path.chomp(".rb").gsub("/", "::")
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.version
|
43
|
+
:version6
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.collect_contents(contents)
|
47
|
+
define_method(:run_plugin) { self.instance_eval(contents) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def provides(*paths)
|
51
|
+
Ohai::Log.debug("Skipping provides '#{paths.join(",")}' for plugin '#{name}'")
|
52
|
+
end
|
53
|
+
|
54
|
+
def require_plugin(plugin_ref)
|
55
|
+
@controller.require_plugin(plugin_ref)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|