Class: Ohai::DSL::Plugin
Defined Under Namespace
Classes: VersionVI, VersionVII
Instance Attribute Summary collapse
Instance Method Summary
collapse
#seconds_to_human
popen4, run_command, #run_command_unix, #run_command_windows, shell_out
Methods included from Mixin::OS
collect_os
Constructor Details
#initialize(data) ⇒ Plugin
Returns a new instance of Plugin.
87
88
89
90
|
# File 'lib/ohai/dsl/plugin.rb', line 87
def initialize(data)
@data = data
@has_run = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
178
179
180
181
182
|
# File 'lib/ohai/dsl/plugin.rb', line 178
def method_missing(name, *args)
return get_attribute(name) if args.length == 0
set_attribute(name, *args)
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
85
86
87
|
# File 'lib/ohai/dsl/plugin.rb', line 85
def data
@data
end
|
Instance Method Details
#[](key) ⇒ Object
110
111
112
|
# File 'lib/ohai/dsl/plugin.rb', line 110
def [](key)
@data[key]
end
|
#[]=(key, value) ⇒ Object
114
115
116
|
# File 'lib/ohai/dsl/plugin.rb', line 114
def []=(key, value)
@data[key] = value
end
|
#each(&block) ⇒ Object
118
119
120
121
122
|
# File 'lib/ohai/dsl/plugin.rb', line 118
def each(&block)
@data.each do |key, value|
block.call(key, value)
end
end
|
#from(cmd) ⇒ Object
134
135
136
137
138
|
# File 'lib/ohai/dsl/plugin.rb', line 134
def from(cmd)
_status, stdout, _stderr = run_command(:command => cmd)
return "" if stdout.nil? || stdout.empty?
stdout.strip
end
|
#from_with_regex(cmd, *regex_list) ⇒ Object
Set the value equal to the stdout of the command, plus run through a regex - the first piece of match data is\ the value.
143
144
145
146
147
148
149
150
151
|
# File 'lib/ohai/dsl/plugin.rb', line 143
def from_with_regex(cmd, *regex_list)
regex_list.flatten.each do |regex|
_status, stdout, _stderr = run_command(:command => cmd)
return "" if stdout.nil? || stdout.empty?
stdout.chomp!.strip
md = stdout.match(regex)
return md[1]
end
end
|
#get_attribute(name) ⇒ Object
158
159
160
|
# File 'lib/ohai/dsl/plugin.rb', line 158
def get_attribute(name)
@data[name]
end
|
#has_key?(name) ⇒ Boolean
Also known as:
attribute?
124
125
126
|
# File 'lib/ohai/dsl/plugin.rb', line 124
def has_key?(name)
@data.has_key?(name)
end
|
#has_run? ⇒ Boolean
102
103
104
|
# File 'lib/ohai/dsl/plugin.rb', line 102
def has_run?
@has_run
end
|
#hint?(name) ⇒ Boolean
162
163
164
|
# File 'lib/ohai/dsl/plugin.rb', line 162
def hint?(name)
Ohai::Hints.hint?(name)
end
|
#reset! ⇒ Object
106
107
108
|
# File 'lib/ohai/dsl/plugin.rb', line 106
def reset!
@has_run = false
end
|
#run ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/ohai/dsl/plugin.rb', line 92
def run
@has_run = true
if Ohai::Config[:disabled_plugins].include?(name)
Ohai::Log.debug("Skipping disabled plugin #{name}")
else
run_plugin
end
end
|
#safe_run ⇒ Object
emulates the old plugin loading behavior
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/ohai/dsl/plugin.rb', line 167
def safe_run
begin
self.run
rescue Ohai::Exceptions::Error => e
raise e
rescue => e
Ohai::Log.debug("Plugin #{self.name} threw #{e.inspect}")
e.backtrace.each { |line| Ohai::Log.debug( line )}
end
end
|
#set(name, *value) ⇒ Object
130
131
132
|
# File 'lib/ohai/dsl/plugin.rb', line 130
def set(name, *value)
set_attribute(name, *value)
end
|
#set_attribute(name, *values) ⇒ Object
153
154
155
156
|
# File 'lib/ohai/dsl/plugin.rb', line 153
def set_attribute(name, *values)
@data[name] = Array18(*values)
@data[name]
end
|