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
@@ -0,0 +1,106 @@
|
|
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 VersionVII < Plugin
|
24
|
+
attr_reader :version
|
25
|
+
attr_reader :source
|
26
|
+
|
27
|
+
def initialize(data)
|
28
|
+
super(data)
|
29
|
+
@source = self.class.sources
|
30
|
+
@version = :version7
|
31
|
+
end
|
32
|
+
|
33
|
+
def name
|
34
|
+
self.class.name.split("Ohai::NamedPlugin::")[1].capitalize.to_sym
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.version
|
38
|
+
:version7
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.sources
|
42
|
+
@source_list ||= []
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.provides_attrs
|
46
|
+
@provides_attrs ||= []
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.depends_attrs
|
50
|
+
@depends_attrs ||= []
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.data_collector
|
54
|
+
@data_collector ||= Mash.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.provides(*attrs)
|
58
|
+
attrs.each do |attr|
|
59
|
+
provides_attrs << attr unless provides_attrs.include?(attr)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.depends(*attrs)
|
64
|
+
attrs.each do |attr|
|
65
|
+
depends_attrs << attr unless depends_attrs.include?(attr)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.collect_data(platform = :default, *other_platforms, &block)
|
70
|
+
[platform, other_platforms].flatten.each do |plat|
|
71
|
+
if data_collector.has_key?(plat)
|
72
|
+
raise Ohai::Exceptions::IllegalPluginDefinition, "collect_data already defined on platform #{plat}"
|
73
|
+
else
|
74
|
+
data_collector[plat] = block
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def dependencies
|
80
|
+
self.class.depends_attrs
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_plugin
|
84
|
+
collector = self.class.data_collector
|
85
|
+
platform = collect_os
|
86
|
+
|
87
|
+
if collector.has_key?(platform)
|
88
|
+
self.instance_eval(&collector[platform])
|
89
|
+
elsif collector.has_key?(:default)
|
90
|
+
self.instance_eval(&collector[:default])
|
91
|
+
else
|
92
|
+
Ohai::Log.debug("No data to collect for plugin #{self.name}. Continuing...")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def provides(*paths)
|
97
|
+
Ohai::Log.warn("[UNSUPPORTED OPERATION] \'provides\' is no longer supported in a \'collect_data\' context. Please specify \'provides\' before collecting plugin data. Ignoring command \'provides #{paths.join(", ")}")
|
98
|
+
end
|
99
|
+
|
100
|
+
def require_plugin(*args)
|
101
|
+
Ohai::Log.warn("[UNSUPPORTED OPERATION] \'require_plugin\' is no longer supported. Please use \'depends\' instead.\nIgnoring plugin(s) #{args.join(", ")}")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/ohai/exception.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.
|
@@ -19,5 +19,14 @@
|
|
19
19
|
module Ohai
|
20
20
|
module Exceptions
|
21
21
|
class Exec < RuntimeError; end
|
22
|
+
class Error < StandardError; end
|
23
|
+
class InvalidPlugin < Error; end
|
24
|
+
class InvalidPluginName < Error; end
|
25
|
+
class IllegalPluginDefinition < Error; end
|
26
|
+
class AttributeNotFound < Error; end
|
27
|
+
class ProviderNotFound < Error; end
|
28
|
+
class DependencyCycle < Error; end
|
29
|
+
class DependencyNotFound < Error; end
|
30
|
+
class AttributeSyntaxError < Error; end
|
22
31
|
end
|
23
32
|
end
|
data/lib/ohai/hints.rb
ADDED
@@ -0,0 +1,48 @@
|
|
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 Hints
|
22
|
+
def self.refresh_hints
|
23
|
+
@hints = Hash.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.hint?(name)
|
27
|
+
@hints ||= Hash.new
|
28
|
+
return @hints[name] if @hints[name]
|
29
|
+
|
30
|
+
Ohai::Config[:hints_path].each do |path|
|
31
|
+
filename = File.join(path, "#{name}.json")
|
32
|
+
if File.exist?(filename)
|
33
|
+
begin
|
34
|
+
json_parser = Yajl::Parser.new
|
35
|
+
hash = json_parser.parse(File.read(filename))
|
36
|
+
@hints[name] = hash || Hash.new # hint
|
37
|
+
# should exist because the file did, even if it didn't
|
38
|
+
# contain anything
|
39
|
+
rescue Yajl::ParseError => e
|
40
|
+
Ohai::Log.error("Could not parse hint file at #{filename}: #{e.message}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
@hints[name]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/ohai/loader.rb
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Claire McQuin (<claire@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 implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'ohai/log'
|
20
|
+
require 'ohai/mash'
|
21
|
+
require 'ohai/dsl'
|
22
|
+
require 'pathname'
|
23
|
+
|
24
|
+
module Ohai
|
25
|
+
|
26
|
+
# Ohai plugin loader. Finds all the plugins in your
|
27
|
+
# `Ohai::Config[:plugin_path]` (supports a single or multiple path setting
|
28
|
+
# here), evaluates them and returns plugin objects.
|
29
|
+
class Loader
|
30
|
+
|
31
|
+
# Simple struct like objects to track the path of a plugin and the root
|
32
|
+
# directory of plugins in which we found it. We don't care about the
|
33
|
+
# relative paths of v7 plugins, but in v6 plugins, dependencies are
|
34
|
+
# specified by calling `require_plugin` with a relative path. To manage
|
35
|
+
# this, we track the path and root of each file as we discover them so we
|
36
|
+
# can feed this into the v6 "dependency solver" as we load them.
|
37
|
+
class PluginFile < Struct.new(:path, :plugin_root)
|
38
|
+
|
39
|
+
# Finds all the *.rb files under the configured paths in :plugin_path
|
40
|
+
def self.find_all_in(plugin_dir)
|
41
|
+
Dir[File.join(plugin_dir, "**", "*.rb")].map do |file|
|
42
|
+
new(file, plugin_dir)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Simple struct to track a v6 plugin's class, file path, and the root of
|
48
|
+
# the plugin dir from which it was loaded.
|
49
|
+
V6PluginClass = Struct.new(:plugin_class, :plugin_path, :plugin_dir_path)
|
50
|
+
|
51
|
+
def initialize(controller)
|
52
|
+
@controller = controller
|
53
|
+
@v6_plugin_classes = []
|
54
|
+
@v7_plugin_classes = []
|
55
|
+
end
|
56
|
+
|
57
|
+
# Searches all plugin paths and returns an Array of PluginFile objects
|
58
|
+
# representing each plugin file.
|
59
|
+
def plugin_files_by_dir
|
60
|
+
Array(Ohai::Config[:plugin_path]).inject([]) do |plugin_files, plugin_path|
|
61
|
+
plugin_files + PluginFile.find_all_in(plugin_path)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_all
|
66
|
+
plugin_files_by_dir.each do |plugin_file|
|
67
|
+
load_plugin_class(plugin_file.path, plugin_file.plugin_root)
|
68
|
+
end
|
69
|
+
|
70
|
+
collect_v6_plugins
|
71
|
+
collect_v7_plugins
|
72
|
+
end
|
73
|
+
|
74
|
+
# Load a specified file as an ohai plugin and creates an instance of it.
|
75
|
+
# Not used by ohai itself, but can be used to load a plugin for testing
|
76
|
+
# purposes.
|
77
|
+
# plugin_dir_path is required when loading a v6 plugin.
|
78
|
+
def load_plugin(plugin_path, plugin_dir_path = nil)
|
79
|
+
plugin_class = load_plugin_class(plugin_path, plugin_dir_path)
|
80
|
+
return nil unless plugin_class.kind_of?(Class)
|
81
|
+
case
|
82
|
+
when plugin_class < Ohai::DSL::Plugin::VersionVI
|
83
|
+
load_v6_plugin(plugin_class, plugin_path, plugin_dir_path)
|
84
|
+
when plugin_class < Ohai::DSL::Plugin::VersionVII
|
85
|
+
load_v7_plugin(plugin_class)
|
86
|
+
else
|
87
|
+
raise Exceptions::IllegalPluginDefinition, "cannot create plugin of type #{plugin_class}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Reads the file specified by `plugin_path` and returns a class object for
|
92
|
+
# the ohai plugin defined therein.
|
93
|
+
#
|
94
|
+
# If `plugin_dir_path` is given, and the file at `plugin_path` is a v6
|
95
|
+
# plugin, the 'relative path' of the plugin (used by `require_plugin()`) is
|
96
|
+
# computed by finding the relative path from `plugin_dir_path` to `plugin_path`
|
97
|
+
def load_plugin_class(plugin_path, plugin_dir_path=nil)
|
98
|
+
# Read the contents of the plugin to understand if it's a V6 or V7 plugin.
|
99
|
+
contents = ""
|
100
|
+
begin
|
101
|
+
contents << IO.read(plugin_path)
|
102
|
+
rescue IOError, Errno::ENOENT
|
103
|
+
Ohai::Log.warn("Unable to open or read plugin at #{plugin_path}")
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
|
107
|
+
# We assume that a plugin is a V7 plugin if it contains Ohai.plugin in its contents.
|
108
|
+
if contents.include?("Ohai.plugin")
|
109
|
+
load_v7_plugin_class(contents, plugin_path)
|
110
|
+
else
|
111
|
+
Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. \
|
112
|
+
Version 6 plugins will not be supported in future releases of Ohai. \
|
113
|
+
Please upgrade your plugin to version 7 plugin syntax. \
|
114
|
+
For more information visit here: docs.opscode.com/ohai_custom.html")
|
115
|
+
|
116
|
+
load_v6_plugin_class(contents, plugin_path, plugin_dir_path)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def collect_provides(plugin)
|
123
|
+
plugin_provides = plugin.class.provides_attrs
|
124
|
+
@controller.provides_map.set_providers_for(plugin, plugin_provides)
|
125
|
+
end
|
126
|
+
|
127
|
+
def v6_dependency_solver
|
128
|
+
@controller.v6_dependency_solver
|
129
|
+
end
|
130
|
+
|
131
|
+
def collect_v6_plugins
|
132
|
+
@v6_plugin_classes.each do |plugin_spec|
|
133
|
+
plugin = load_v6_plugin(plugin_spec.plugin_class, plugin_spec.plugin_path, plugin_spec.plugin_dir_path)
|
134
|
+
loaded_v6_plugin(plugin, plugin_spec.plugin_path, plugin_spec.plugin_dir_path)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def collect_v7_plugins
|
139
|
+
@v7_plugin_classes.each do |plugin_class|
|
140
|
+
load_v7_plugin(plugin_class)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def load_v6_plugin_class(contents, plugin_path, plugin_dir_path)
|
145
|
+
plugin_class = Class.new(Ohai::DSL::Plugin::VersionVI) { collect_contents(contents) }
|
146
|
+
@v6_plugin_classes << V6PluginClass.new(plugin_class, plugin_path, plugin_dir_path)
|
147
|
+
plugin_class
|
148
|
+
end
|
149
|
+
|
150
|
+
def load_v6_plugin(plugin_class, plugin_path, plugin_dir_path)
|
151
|
+
plugin_class.new(@controller, plugin_path, plugin_dir_path)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Capture the plugin in @v6_dependency_solver if it is a V6 plugin
|
155
|
+
# to be able to resolve V6 dependencies later on.
|
156
|
+
# We are using the partial path in the dep solver as a key.
|
157
|
+
def loaded_v6_plugin(plugin, plugin_file_path, plugin_dir_path)
|
158
|
+
partial_path = Pathname.new(plugin_file_path).relative_path_from(Pathname.new(plugin_dir_path)).to_s
|
159
|
+
|
160
|
+
unless v6_dependency_solver.has_key?(partial_path)
|
161
|
+
v6_dependency_solver[partial_path] = plugin
|
162
|
+
else
|
163
|
+
Ohai::Log.debug("Plugin '#{plugin_file_path}' is already loaded.")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def load_v7_plugin_class(contents, plugin_path)
|
168
|
+
plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path)
|
169
|
+
unless plugin_class.kind_of?(Class) and plugin_class < Ohai::DSL::Plugin
|
170
|
+
raise Ohai::Exceptions::IllegalPluginDefinition, "Plugin file cannot contain any statements after the plugin definition"
|
171
|
+
end
|
172
|
+
plugin_class.sources << plugin_path
|
173
|
+
@v7_plugin_classes << plugin_class unless @v7_plugin_classes.include?(plugin_class)
|
174
|
+
plugin_class
|
175
|
+
rescue SystemExit, Interrupt
|
176
|
+
raise
|
177
|
+
rescue Ohai::Exceptions::InvalidPluginName => e
|
178
|
+
Ohai::Log.warn("Plugin Name Error: <#{plugin_path}>: #{e.message}")
|
179
|
+
rescue Ohai::Exceptions::IllegalPluginDefinition => e
|
180
|
+
Ohai::Log.warn("Plugin Definition Error: <#{plugin_path}>: #{e.message}")
|
181
|
+
rescue NoMethodError => e
|
182
|
+
Ohai::Log.warn("Plugin Method Error: <#{plugin_path}>: unsupported operation \'#{e.name}\'")
|
183
|
+
rescue SyntaxError => e
|
184
|
+
# split on occurrences of
|
185
|
+
# <env>: syntax error,
|
186
|
+
# <env>:##: syntax error,
|
187
|
+
# to remove from error message
|
188
|
+
parts = e.message.split(/<.*>[:[0-9]+]*: syntax error, /)
|
189
|
+
parts.each do |part|
|
190
|
+
next if part.length == 0
|
191
|
+
Ohai::Log.warn("Plugin Syntax Error: <#{plugin_path}>: #{part}")
|
192
|
+
end
|
193
|
+
rescue Exception, Errno::ENOENT => e
|
194
|
+
Ohai::Log.warn("Plugin Error: <#{plugin_path}>: #{e.message}")
|
195
|
+
Ohai::Log.debug("Plugin Error: <#{plugin_path}>: #{e.inspect}, #{e.backtrace.join('\n')}")
|
196
|
+
end
|
197
|
+
|
198
|
+
def load_v7_plugin(plugin_class)
|
199
|
+
plugin = plugin_class.new(@controller.data)
|
200
|
+
collect_provides(plugin)
|
201
|
+
plugin
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
data/lib/ohai/mixin/command.rb
CHANGED
@@ -23,11 +23,18 @@ require 'stringio'
|
|
23
23
|
require 'tmpdir'
|
24
24
|
require 'fcntl'
|
25
25
|
require 'etc'
|
26
|
-
require '
|
26
|
+
require 'mixlib/shellout'
|
27
27
|
|
28
28
|
module Ohai
|
29
29
|
module Mixin
|
30
30
|
module Command
|
31
|
+
def shell_out(cmd)
|
32
|
+
m = Mixlib::ShellOut.new(cmd)
|
33
|
+
m.run_command
|
34
|
+
m
|
35
|
+
end
|
36
|
+
|
37
|
+
module_function :shell_out
|
31
38
|
|
32
39
|
def run_command(args={})
|
33
40
|
if args.has_key?(:creates)
|
@@ -48,11 +55,6 @@ module Ohai
|
|
48
55
|
status = nil
|
49
56
|
Dir.chdir(args[:cwd]) do
|
50
57
|
status, stdout_string, stderr_string = run_command_backend(args[:command], args[:timeout])
|
51
|
-
# systemu returns 42 when it hits unexpected errors
|
52
|
-
if status.exitstatus == 42 and stderr_string == ""
|
53
|
-
stderr_string = "Failed to run: #{args[:command]}, assuming command not found"
|
54
|
-
Ohai::Log.debug(stderr_string)
|
55
|
-
end
|
56
58
|
|
57
59
|
if stdout_string
|
58
60
|
Ohai::Log.debug("---- Begin #{args[:command]} STDOUT ----")
|
@@ -101,18 +103,12 @@ module Ohai
|
|
101
103
|
end
|
102
104
|
|
103
105
|
def run_command_windows(command, timeout)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
Ohai::Log.error("#{command} exceeded timeout #{timeout}")
|
111
|
-
raise(e)
|
112
|
-
end
|
113
|
-
else
|
114
|
-
systemu(command)
|
115
|
-
end
|
106
|
+
shellout_opts = {}
|
107
|
+
shellout_opts[:timeout] = timeout if timeout
|
108
|
+
|
109
|
+
m = Mixlib::ShellOut.new(command, shellout_opts)
|
110
|
+
m.run_command
|
111
|
+
[m.status, m.stdout, m.stderr]
|
116
112
|
end
|
117
113
|
|
118
114
|
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Serdar Sutay (<serdar@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 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 Mixin
|
22
|
+
module ConstantHelper
|
23
|
+
|
24
|
+
def remove_constants
|
25
|
+
new_object_constants = Object.constants - @object_pristine.constants
|
26
|
+
new_object_constants.each do |constant|
|
27
|
+
Object.send(:remove_const, constant) unless Object.const_get(constant).is_a?(Module)
|
28
|
+
end
|
29
|
+
|
30
|
+
recursive_remove_constants(Ohai::NamedPlugin)
|
31
|
+
end
|
32
|
+
|
33
|
+
def recursive_remove_constants(object)
|
34
|
+
if object.respond_to?(:constants)
|
35
|
+
object.constants.each do |const|
|
36
|
+
next unless strict_const_defined?(object, const)
|
37
|
+
recursive_remove_constants(object.const_get(const))
|
38
|
+
object.send(:remove_const, const)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def strict_const_defined?(object, const)
|
44
|
+
if object.method(:const_defined?).arity == 1
|
45
|
+
object.const_defined?(const)
|
46
|
+
else
|
47
|
+
object.const_defined?(const, false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|