rightscale-ohai 0.3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +98 -0
- data/Rakefile +59 -0
- data/bin/ohai +78 -0
- data/lib/ohai/config.rb +118 -0
- data/lib/ohai/exception.rb +23 -0
- data/lib/ohai/log/formatter.rb +57 -0
- data/lib/ohai/log.rb +89 -0
- data/lib/ohai/mixin/command.rb +203 -0
- data/lib/ohai/mixin/from_file.rb +36 -0
- data/lib/ohai/mixin/string.rb +29 -0
- data/lib/ohai/plugins/cloud.rb +35 -0
- data/lib/ohai/plugins/command.rb +21 -0
- data/lib/ohai/plugins/darwin/filesystem.rb +57 -0
- data/lib/ohai/plugins/darwin/hostname.rb +22 -0
- data/lib/ohai/plugins/darwin/kernel.rb +37 -0
- data/lib/ohai/plugins/darwin/network.rb +187 -0
- data/lib/ohai/plugins/darwin/platform.rb +36 -0
- data/lib/ohai/plugins/darwin/ps.rb +23 -0
- data/lib/ohai/plugins/darwin/ssh_host_key.rb +25 -0
- data/lib/ohai/plugins/darwin/system_profiler.rb +33 -0
- data/lib/ohai/plugins/darwin/uptime.rb +32 -0
- data/lib/ohai/plugins/dmi.rb +59 -0
- data/lib/ohai/plugins/ec2.rb +100 -0
- data/lib/ohai/plugins/erlang.rb +40 -0
- data/lib/ohai/plugins/freebsd/cpu.rb +52 -0
- data/lib/ohai/plugins/freebsd/filesystem.rb +57 -0
- data/lib/ohai/plugins/freebsd/hostname.rb +22 -0
- data/lib/ohai/plugins/freebsd/kernel.rb +37 -0
- data/lib/ohai/plugins/freebsd/memory.rb +50 -0
- data/lib/ohai/plugins/freebsd/network.rb +112 -0
- data/lib/ohai/plugins/freebsd/platform.rb +23 -0
- data/lib/ohai/plugins/freebsd/ps.rb +24 -0
- data/lib/ohai/plugins/freebsd/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/freebsd/uptime.rb +32 -0
- data/lib/ohai/plugins/freebsd/virtualization.rb +66 -0
- data/lib/ohai/plugins/hostname.rb +27 -0
- data/lib/ohai/plugins/java.rb +36 -0
- data/lib/ohai/plugins/kernel.rb +33 -0
- data/lib/ohai/plugins/keys.rb +22 -0
- data/lib/ohai/plugins/languages.rb +21 -0
- data/lib/ohai/plugins/linux/block_device.rb +38 -0
- data/lib/ohai/plugins/linux/cpu.rb +60 -0
- data/lib/ohai/plugins/linux/filesystem.rb +57 -0
- data/lib/ohai/plugins/linux/hostname.rb +26 -0
- data/lib/ohai/plugins/linux/kernel.rb +33 -0
- data/lib/ohai/plugins/linux/lsb.rb +38 -0
- data/lib/ohai/plugins/linux/memory.rb +83 -0
- data/lib/ohai/plugins/linux/network.rb +112 -0
- data/lib/ohai/plugins/linux/platform.rb +43 -0
- data/lib/ohai/plugins/linux/ps.rb +23 -0
- data/lib/ohai/plugins/linux/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/linux/uptime.rb +28 -0
- data/lib/ohai/plugins/linux/virtualization.rb +77 -0
- data/lib/ohai/plugins/network.rb +52 -0
- data/lib/ohai/plugins/ohai_time.rb +21 -0
- data/lib/ohai/plugins/os.rb +43 -0
- data/lib/ohai/plugins/perl.rb +37 -0
- data/lib/ohai/plugins/platform.rb +25 -0
- data/lib/ohai/plugins/python.rb +37 -0
- data/lib/ohai/plugins/rightscale.rb +53 -0
- data/lib/ohai/plugins/ruby.rb +37 -0
- data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
- data/lib/ohai/plugins/solaris2/hostname.rb +22 -0
- data/lib/ohai/plugins/solaris2/kernel.rb +21 -0
- data/lib/ohai/plugins/solaris2/network.rb +141 -0
- data/lib/ohai/plugins/solaris2/platform.rb +33 -0
- data/lib/ohai/plugins/solaris2/ps.rb +23 -0
- data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/uptime.rb +42 -0
- data/lib/ohai/plugins/virtualization.rb +86 -0
- data/lib/ohai/plugins/windows/filesystem.rb +44 -0
- data/lib/ohai/plugins/windows/hostname.rb +25 -0
- data/lib/ohai/plugins/windows/kernel.rb +75 -0
- data/lib/ohai/plugins/windows/network.rb +114 -0
- data/lib/ohai/plugins/windows/platform.rb +26 -0
- data/lib/ohai/system.rb +226 -0
- data/lib/ohai.rb +27 -0
- data/spec/ohai/log/log_formatter_spec.rb +50 -0
- data/spec/ohai/log_spec.rb +63 -0
- data/spec/ohai/mixin/from_file_spec.rb +53 -0
- data/spec/ohai/plugins/cloud_spec.rb +64 -0
- data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
- data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
- data/spec/ohai/plugins/dmi_spec.rb +73 -0
- data/spec/ohai/plugins/ec2_spec.rb +77 -0
- data/spec/ohai/plugins/erlang_spec.rb +63 -0
- data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
- data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
- data/spec/ohai/plugins/hostname_spec.rb +39 -0
- data/spec/ohai/plugins/java_spec.rb +70 -0
- data/spec/ohai/plugins/kernel_spec.rb +43 -0
- data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
- data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
- data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
- data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
- data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
- data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
- data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
- data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
- data/spec/ohai/plugins/os_spec.rb +58 -0
- data/spec/ohai/plugins/perl_spec.rb +89 -0
- data/spec/ohai/plugins/platform_spec.rb +56 -0
- data/spec/ohai/plugins/python_spec.rb +53 -0
- data/spec/ohai/plugins/rightscale_spec.rb +71 -0
- data/spec/ohai/plugins/ruby_spec.rb +51 -0
- data/spec/ohai/system_spec.rb +130 -0
- data/spec/ohai_spec.rb +27 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +66 -0
- metadata +209 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 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 'ruby-wmi'
|
20
|
+
require 'socket'
|
21
|
+
|
22
|
+
host = WMI::Win32_ComputerSystem.find(:first)
|
23
|
+
hostname "#{host.Name}"
|
24
|
+
#hostname "#{Socket.gethostname}"
|
25
|
+
fqdn "#{Socket.gethostbyname(Socket.gethostname).first}"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#
|
2
|
+
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 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 'ruby-wmi'
|
20
|
+
|
21
|
+
def machine_lookup(sys_type)
|
22
|
+
return "i386" if sys_type.eql?("X86-based PC")
|
23
|
+
return "x86_64" if sys_type.eql?("x64-based PC")
|
24
|
+
sys_type
|
25
|
+
end
|
26
|
+
|
27
|
+
def os_lookup(sys_type)
|
28
|
+
return "Unknown" if sys_type.to_s.eql?("0")
|
29
|
+
return "Other" if sys_type.to_s.eql?("1")
|
30
|
+
return "MSDOS" if sys_type.to_s.eql?("14")
|
31
|
+
return "WIN3x" if sys_type.to_s.eql?("15")
|
32
|
+
return "WIN95" if sys_type.to_s.eql?("16")
|
33
|
+
return "WIN98" if sys_type.to_s.eql?("17")
|
34
|
+
return "WINNT" if sys_type.to_s.eql?("18")
|
35
|
+
return "WINCE" if sys_type.to_s.eql?("19")
|
36
|
+
return nil
|
37
|
+
end
|
38
|
+
|
39
|
+
host = WMI::Win32_OperatingSystem.find(:first)
|
40
|
+
kernel[:os_info] = Mash.new
|
41
|
+
host.properties_.each do |p|
|
42
|
+
kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name]
|
43
|
+
end
|
44
|
+
|
45
|
+
kernel[:name] = "#{kernel[:os_info][:caption]}"
|
46
|
+
kernel[:release] = "#{kernel[:os_info][:version]}"
|
47
|
+
kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
|
48
|
+
kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
|
49
|
+
|
50
|
+
host = WMI::Win32_ComputerSystem.find(:first)
|
51
|
+
kernel[:cs_info] = Mash.new
|
52
|
+
host.properties_.each do |p|
|
53
|
+
kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name]
|
54
|
+
end
|
55
|
+
|
56
|
+
kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
|
57
|
+
|
58
|
+
kext = Mash.new
|
59
|
+
pnp_drivers = Mash.new
|
60
|
+
|
61
|
+
drivers = WMI::Win32_PnPSignedDriver.find(:all)
|
62
|
+
drivers.each do |driver|
|
63
|
+
pnp_drivers[driver.DeviceID] = Mash.new
|
64
|
+
driver.properties_.each do |p|
|
65
|
+
pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver[p.name]
|
66
|
+
end
|
67
|
+
if driver.DeviceName
|
68
|
+
kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
|
69
|
+
kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version]
|
70
|
+
kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
kernel[:pnp_drivers] = pnp_drivers
|
75
|
+
kernel[:modules] = kext
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#
|
2
|
+
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 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 'ruby-wmi'
|
20
|
+
|
21
|
+
def encaps_lookup(encap)
|
22
|
+
return "Ethernet" if encap.eql?("Ethernet 802.3")
|
23
|
+
encap
|
24
|
+
end
|
25
|
+
|
26
|
+
def derive_bcast(ipaddr, ipmask, zero_bcast = false)
|
27
|
+
begin
|
28
|
+
ipaddr_int = ipaddr.split(".").collect{ |x| x.to_i}.pack("C4").unpack("N").first
|
29
|
+
ipmask_int = ipmask.split(".").collect{ |x| x.to_i}.pack("C4").unpack("N").first
|
30
|
+
if zero_bcast
|
31
|
+
bcast_int = ipaddr_int & ipmask_int
|
32
|
+
else
|
33
|
+
bcast_int = ipaddr_int | 2 ** 32 - ipmask_int - 1
|
34
|
+
end
|
35
|
+
bcast = [bcast_int].pack("N").unpack("C4").join(".")
|
36
|
+
return bcast
|
37
|
+
rescue
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
iface = Mash.new
|
43
|
+
iface_config = Mash.new
|
44
|
+
iface_instance = Mash.new
|
45
|
+
|
46
|
+
adapters = WMI::Win32_NetworkAdapterConfiguration.find(:all)
|
47
|
+
adapters.each do |adapter|
|
48
|
+
i = adapter.Index
|
49
|
+
iface_config[i] = Mash.new
|
50
|
+
adapter.properties_.each do |p|
|
51
|
+
iface_config[i][p.name.wmi_underscore.to_sym] = adapter[p.name]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
adapters = WMI::Win32_NetworkAdapter.find(:all)
|
56
|
+
adapters.each do |adapter|
|
57
|
+
i = adapter.Index
|
58
|
+
iface_instance[i] = Mash.new
|
59
|
+
adapter.properties_.each do |p|
|
60
|
+
iface_instance[i][p.name.wmi_underscore.to_sym] = adapter[p.name]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
iface_instance.keys.each do |i|
|
65
|
+
if iface_config[i][:ip_enabled] and iface_instance[i][:net_connection_id] and iface_instance[i][:interface_index]
|
66
|
+
cint = sprintf("0x%X", iface_instance[i][:interface_index])
|
67
|
+
iface[cint] = Mash.new
|
68
|
+
iface[cint][:configuration] = iface_config[i]
|
69
|
+
iface[cint][:instance] = iface_instance[i]
|
70
|
+
|
71
|
+
iface[cint][:counters] = Mash.new
|
72
|
+
iface[cint][:addresses] = Mash.new
|
73
|
+
iface[cint][:configuration][:ip_address].each_index do |i|
|
74
|
+
begin
|
75
|
+
if iface[cint][:configuration][:ip_address][i] =~ /./
|
76
|
+
iface[cint][:addresses][iface[cint][:configuration][:ip_address][i]] = {
|
77
|
+
"family" => "inet",
|
78
|
+
"netmask" => iface[cint][:configuration][:ip_subnet][i],
|
79
|
+
"broadcast" => derive_bcast( iface[cint][:configuration][:ip_address][i],
|
80
|
+
iface[cint][:configuration][:ip_subnet][i],
|
81
|
+
iface[cint][:configuration][:ip_use_zero_broadcast]
|
82
|
+
)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
rescue
|
86
|
+
end
|
87
|
+
end
|
88
|
+
iface[cint][:configuration][:mac_address].each do |mac_addr|
|
89
|
+
iface[cint][:addresses][mac_addr] = {
|
90
|
+
"family" => "lladdr"
|
91
|
+
}
|
92
|
+
end
|
93
|
+
iface[cint][:mtu] = iface[cint][:configuration][:mtu]
|
94
|
+
iface[cint][:type] = iface[cint][:instance][:adapter_type]
|
95
|
+
iface[cint][:arp] = {}
|
96
|
+
iface[cint][:encapsulation] = encaps_lookup(iface[cint][:instance][:adapter_type])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
cint=nil
|
101
|
+
from("arp /a").split("\n").each do |line|
|
102
|
+
if line == ""
|
103
|
+
cint = nil
|
104
|
+
end
|
105
|
+
if line =~ /^Interface:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+[-]+\s+(0x\d+)/
|
106
|
+
cint = $2
|
107
|
+
end
|
108
|
+
next unless iface[cint]
|
109
|
+
if line =~ /^\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-fA-F0-9\:-]+)/
|
110
|
+
iface[cint][:arp][$1] = $2.gsub("-",":").downcase
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
network["interfaces"] = iface
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 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
|
+
# After long discussion in IRC the "powers that be" have come to a concensus
|
20
|
+
# that there is no other Windows platforms exist that were not based on the
|
21
|
+
# Windows_NT kernel, so we herby decree that "windows" will refer to all
|
22
|
+
# platforms built upon the Windows_NT kernel and have access to win32 or win64
|
23
|
+
# subsystems.
|
24
|
+
platform os
|
25
|
+
platform_version kernel['release']
|
26
|
+
|
data/lib/ohai/system.rb
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 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 'rubygems'
|
20
|
+
require 'extlib'
|
21
|
+
require 'ohai/log'
|
22
|
+
require 'ohai/mixin/from_file'
|
23
|
+
require 'ohai/mixin/command'
|
24
|
+
require 'ohai/mixin/string'
|
25
|
+
require 'json'
|
26
|
+
|
27
|
+
module Ohai
|
28
|
+
class System
|
29
|
+
attr_accessor :data, :seen_plugins
|
30
|
+
|
31
|
+
include Ohai::Mixin::FromFile
|
32
|
+
include Ohai::Mixin::Command
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@data = Mash.new
|
36
|
+
@seen_plugins = Hash.new
|
37
|
+
@providers = Mash.new
|
38
|
+
@plugin_path = ""
|
39
|
+
end
|
40
|
+
|
41
|
+
def [](key)
|
42
|
+
@data[key]
|
43
|
+
end
|
44
|
+
|
45
|
+
def []=(key, value)
|
46
|
+
@data[key] = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def each(&block)
|
50
|
+
@data.each do |key, value|
|
51
|
+
block.call(key, value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def attribute?(name)
|
56
|
+
@data.has_key?(name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def set(name, *value)
|
60
|
+
set_attribute(name, *value)
|
61
|
+
end
|
62
|
+
|
63
|
+
def from(cmd)
|
64
|
+
status, stdout, stderr = run_command(:command => cmd)
|
65
|
+
return "" if stdout.nil?
|
66
|
+
stdout.chomp!.strip
|
67
|
+
end
|
68
|
+
|
69
|
+
def provides(*paths)
|
70
|
+
paths.each do |path|
|
71
|
+
parts = path.split('/')
|
72
|
+
h = @providers
|
73
|
+
unless parts.length == 0
|
74
|
+
parts.shift if parts[0].length == 0
|
75
|
+
parts.each do |part|
|
76
|
+
h[part] ||= Mash.new
|
77
|
+
h = h[part]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
h[:_providers] ||= []
|
81
|
+
h[:_providers] << @plugin_path
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Set the value equal to the stdout of the command, plus run through a regex - the first piece of match data is the value.
|
86
|
+
def from_with_regex(cmd, *regex_list)
|
87
|
+
regex_list.flatten.each do |regex|
|
88
|
+
status, stdout, stderr = run_command(:command => cmd)
|
89
|
+
return "" if stdout.nil?
|
90
|
+
stdout.chomp!.strip
|
91
|
+
md = stdout.match(regex)
|
92
|
+
return md[1]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def set_attribute(name, *value)
|
97
|
+
@data[name] = *value
|
98
|
+
@data[name]
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_attribute(name)
|
102
|
+
@data[name]
|
103
|
+
end
|
104
|
+
|
105
|
+
def all_plugins
|
106
|
+
require_plugin('os')
|
107
|
+
|
108
|
+
Ohai::Config[:plugin_path].each do |path|
|
109
|
+
[
|
110
|
+
Dir[File.join(path, '*')],
|
111
|
+
Dir[File.join(path, @data[:os], '**', '*')]
|
112
|
+
].flatten.each do |file|
|
113
|
+
file_regex = Regexp.new("#{path}#{File::SEPARATOR}(.+).rb$")
|
114
|
+
md = file_regex.match(file)
|
115
|
+
if md
|
116
|
+
plugin_name = md[1].gsub(File::SEPARATOR, "::")
|
117
|
+
require_plugin(plugin_name) unless @seen_plugins.has_key?(plugin_name)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def collect_providers(providers)
|
124
|
+
refreshments = []
|
125
|
+
if providers.is_a?(Mash)
|
126
|
+
providers.keys.each do |provider|
|
127
|
+
if provider.eql?("_providers")
|
128
|
+
refreshments << providers[provider]
|
129
|
+
else
|
130
|
+
refreshments << collect_providers(providers[provider])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
else
|
134
|
+
refreshments << providers
|
135
|
+
end
|
136
|
+
refreshments.flatten.uniq
|
137
|
+
end
|
138
|
+
|
139
|
+
def refresh_plugins(path = '/')
|
140
|
+
parts = path.split('/')
|
141
|
+
if parts.length == 0
|
142
|
+
h = @providers
|
143
|
+
else
|
144
|
+
parts.shift if parts[0].length == 0
|
145
|
+
h = @providers
|
146
|
+
parts.each do |part|
|
147
|
+
break unless h.has_key?(part)
|
148
|
+
h = h[part]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
refreshments = collect_providers(h)
|
153
|
+
Ohai::Log.debug("Refreshing plugins: #{refreshments.join(", ")}")
|
154
|
+
|
155
|
+
refreshments.each do |r|
|
156
|
+
@seen_plugins.delete(r) if @seen_plugins.has_key?(r)
|
157
|
+
end
|
158
|
+
refreshments.each do |r|
|
159
|
+
require_plugin(r) unless @seen_plugins.has_key?(r)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def require_plugin(plugin_name, force=false)
|
164
|
+
unless force
|
165
|
+
return true if @seen_plugins[plugin_name]
|
166
|
+
end
|
167
|
+
|
168
|
+
@plugin_path = plugin_name
|
169
|
+
|
170
|
+
filename = "#{plugin_name.gsub("::", File::SEPARATOR)}.rb"
|
171
|
+
|
172
|
+
Ohai::Config[:plugin_path].each do |path|
|
173
|
+
check_path = File.expand_path(File.join(path, filename))
|
174
|
+
begin
|
175
|
+
@seen_plugins[plugin_name] = true
|
176
|
+
Ohai::Log.debug("Loading plugin #{plugin_name}")
|
177
|
+
from_file(check_path)
|
178
|
+
return true
|
179
|
+
rescue IOError => e
|
180
|
+
Ohai::Log.debug("No #{plugin_name} at #{check_path}")
|
181
|
+
rescue Exception,Errno::ENOENT => e
|
182
|
+
Ohai::Log.debug("Plugin #{plugin_name} threw exception #{e.inspect}")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Sneaky! Lets us stub out require_plugin when testing plugins, but still
|
188
|
+
# call the real require_plugin to kick the whole thing off.
|
189
|
+
alias :_require_plugin :require_plugin
|
190
|
+
|
191
|
+
# Serialize this object as a hash
|
192
|
+
def to_json(*a)
|
193
|
+
output = @data.clone
|
194
|
+
output["json_class"] = self.class.name
|
195
|
+
output.to_json(*a)
|
196
|
+
end
|
197
|
+
|
198
|
+
# Pretty Print this object as JSON
|
199
|
+
def json_pretty_print
|
200
|
+
JSON.pretty_generate(@data)
|
201
|
+
end
|
202
|
+
|
203
|
+
def attributes_print(a)
|
204
|
+
JSON.pretty_generate(@data[a])
|
205
|
+
end
|
206
|
+
# Create an Ohai::System from JSON
|
207
|
+
def self.json_create(o)
|
208
|
+
ohai = new
|
209
|
+
o.each do |key, value|
|
210
|
+
ohai.data[key] = value unless key == "json_class"
|
211
|
+
end
|
212
|
+
ohai
|
213
|
+
end
|
214
|
+
|
215
|
+
def method_missing(name, *args)
|
216
|
+
return get_attribute(name) if args.length == 0
|
217
|
+
|
218
|
+
set_attribute(name, *args)
|
219
|
+
end
|
220
|
+
|
221
|
+
private
|
222
|
+
def load_plugin_file
|
223
|
+
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|