Class: Ohai::DSL::Plugin::VersionVII
- Inherits:
-
Ohai::DSL::Plugin
- Object
- Ohai::DSL::Plugin
- Ohai::DSL::Plugin::VersionVII
- Defined in:
- lib/ohai/dsl/plugin/versionvii.rb
Overview
The class for the “Version 7” plugin format we introduced in Ohai 7. This is the 2nd generation of Ohai plugin and the previous generation (V6) was removed in Ohai 14
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Attributes inherited from Ohai::DSL::Plugin
Class Method Summary collapse
-
.collect_data(platform = :default, *other_platforms, &block) ⇒ Object
define data collection methodology per platform.
-
.data_collector ⇒ Mash
A block per platform for actually performing data collection constructed by the collect_data method.
-
.depends(*attrs) ⇒ Object
set the attributes depended on by the plugin.
- .depends_attrs ⇒ Object
-
.optional(opt = true) ⇒ Object
set the plugin optional state.
-
.optional? ⇒ Boolean
check if the plugin is optional.
-
.provides(*attrs) ⇒ Object
set the attributes provided by the plugin.
- .provides_attrs ⇒ Object
-
.sources ⇒ Array
the source of the plugin on disk.
-
.version ⇒ Symbol
return that we’re a v7 plugin.
Instance Method Summary collapse
- #configuration(option, *options) ⇒ Object
- #dependencies ⇒ Array
-
#initialize(data, logger) ⇒ VersionVII
constructor
A new instance of VersionVII.
-
#name ⇒ String
the plugin name we use through Ohai (Foo) vs.
- #optional? ⇒ Boolean
- #provides(*paths) ⇒ Object
- #require_plugin(*args) ⇒ Object
- #run_plugin ⇒ Object
Methods inherited from Ohai::DSL::Plugin
#[], #[]=, #attribute?, #each, #from, #from_with_regex, #get_attribute, #has_key?, #has_run?, #hint?, #method_missing, #reset!, #run, #safe_run, #set, #set_attribute
Methods included from Util::FileHelper
Methods included from Mixin::SecondsToHuman
Methods included from Mixin::Command
Methods included from Mixin::OS
Constructor Details
#initialize(data, logger) ⇒ VersionVII
Returns a new instance of VersionVII.
29 30 31 32 33 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 29 def initialize(data, logger) super(data, logger) @source = self.class.sources @version = :version7 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ohai::DSL::Plugin
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
27 28 29 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 27 def source @source end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
26 27 28 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 26 def version @version end |
Class Method Details
.collect_data(platform = :default, *other_platforms, &block) ⇒ Object
define data collection methodology per platform
109 110 111 112 113 114 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 109 def self.collect_data(platform = :default, *other_platforms, &block) [platform, other_platforms].flatten.each do |plat| Ohai::Log.warn("collect_data already defined on platform '#{plat}' for #{self}, last plugin seen will be used") if data_collector.key?(plat) data_collector[plat] = block end end |
.data_collector ⇒ Mash
A block per platform for actually performing data collection constructed by the collect_data method
68 69 70 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 68 def self.data_collector @data_collector ||= Mash.new end |
.depends(*attrs) ⇒ Object
set the attributes depended on by the plugin
84 85 86 87 88 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 84 def self.depends(*attrs) attrs.each do |attr| depends_attrs << attr unless depends_attrs.include?(attr) end end |
.depends_attrs ⇒ Object
60 61 62 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 60 def self.depends_attrs @depends_attrs ||= [] end |
.optional(opt = true) ⇒ Object
set the plugin optional state
93 94 95 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 93 def self.optional(opt = true) @optional = opt end |
.optional? ⇒ Boolean
check if the plugin is optional
100 101 102 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 100 def self.optional? !!@optional end |
.provides(*attrs) ⇒ Object
set the attributes provided by the plugin
75 76 77 78 79 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 75 def self.provides(*attrs) attrs.each do |attr| provides_attrs << attr unless provides_attrs.include?(attr) end end |
.provides_attrs ⇒ Object
56 57 58 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 56 def self.provides_attrs @provides_attrs ||= [] end |
.sources ⇒ Array
the source of the plugin on disk. This is an array since a plugin may exist for multiple platforms and this would include each of those platform specific file paths
52 53 54 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 52 def self.sources @source_list ||= [] end |
.version ⇒ Symbol
return that we’re a v7 plugin
45 46 47 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 45 def self.version :version7 end |
Instance Method Details
#configuration(option, *options) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 146 def configuration(option, *) return nil if plugin_config.nil? || !plugin_config.key?(option) value = plugin_config[option] .each do |opt| return nil unless value.key?(opt) value = value[opt] end value end |
#dependencies ⇒ Array
117 118 119 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 117 def dependencies self.class.depends_attrs end |
#name ⇒ String
the plugin name we use through Ohai (Foo) vs. the class name (Ohai::NamedPlugin::Foo)
38 39 40 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 38 def name self.class.name.split("Ohai::NamedPlugin::")[1].to_sym end |
#optional? ⇒ Boolean
134 135 136 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 134 def optional? self.class.optional? end |
#provides(*paths) ⇒ Object
138 139 140 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 138 def provides(*paths) logger.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(", ")}") end |
#require_plugin(*args) ⇒ Object
142 143 144 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 142 def require_plugin(*args) logger.warn("[UNSUPPORTED OPERATION] \'require_plugin\' is no longer supported. Please use \'depends\' instead.\nIgnoring plugin(s) #{args.join(", ")}") end |
#run_plugin ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ohai/dsl/plugin/versionvii.rb', line 121 def run_plugin collector = self.class.data_collector platform = collect_os if collector.key?(platform) instance_eval(&collector[platform]) elsif collector.key?(:default) instance_eval(&collector[:default]) else logger.trace("Plugin #{name}: No data to collect. Skipping...") end end |