module MCollective::Data
Public Class Methods
[](plugin)
click to toggle source
# File lib/mcollective/data.rb 26 def self.[](plugin) 27 PluginManager[pluginname(plugin)] 28 end
ddl(plugin)
click to toggle source
# File lib/mcollective/data.rb 37 def self.ddl(plugin) 38 DDL.new(pluginname(plugin), :data) 39 end
ddl_has_output?(ddl, output)
click to toggle source
# File lib/mcollective/data.rb 62 def self.ddl_has_output?(ddl, output) 63 ddl.entities[:data][:output].include?(output.to_sym) rescue false 64 end
ddl_transform_input(ddl, input)
click to toggle source
For an input where the DDL
requests a boolean or some number this will convert the input to the right type where possible else just returns the origin input unedited
if anything here goes wrong just return the input value this is not really the end of the world or anything since all that will happen is that DDL
validation will fail and the user will get an error, no need to be too defensive here
# File lib/mcollective/data.rb 74 def self.ddl_transform_input(ddl, input) 75 begin 76 type = ddl.entities[:data][:input][:query][:type] 77 78 case type 79 when :boolean 80 return DDL.string_to_boolean(input) 81 82 when :number, :integer, :float 83 return DDL.string_to_number(input) 84 end 85 rescue 86 end 87 88 return input 89 end
ddl_validate(ddl, argument)
click to toggle source
# File lib/mcollective/data.rb 41 def self.ddl_validate(ddl, argument) 42 name = ddl.meta[:name] 43 query = ddl.entities[:data] 44 45 raise DDLValidationError, "No dataquery has been defined in the DDL for data plugin #{name}" unless query 46 47 input = query.fetch(:input, {}) 48 output = query.fetch(:output, {}) 49 50 raise DDLValidationError, "No output has been defined in the DDL for data plugin #{name}" if output.keys.empty? 51 52 if input[:query] 53 return true if argument.nil? && input[:query][:optional] 54 55 ddl.validate_input_argument(input, :query, argument) 56 else 57 raise("No data plugin argument was declared in the %s DDL but an input was supplied" % name) if argument 58 return true 59 end 60 end
load_data_sources()
click to toggle source
# File lib/mcollective/data.rb 6 def self.load_data_sources 7 PluginManager.find_and_load("data") 8 9 PluginManager.grep(/_data$/).each do |plugin| 10 begin 11 unless PluginManager[plugin].class.activate? 12 Log.debug("Disabling data plugin %s due to plugin activation policy" % plugin) 13 PluginManager.delete(plugin) 14 end 15 rescue Exception => e 16 Log.debug("Disabling data plugin %s due to exception #{e.class}: #{e}" % plugin) 17 PluginManager.delete(plugin) 18 end 19 end 20 end
method_missing(method, *args)
click to toggle source
Data.package(“httpd”).architecture
Calls superclass method
# File lib/mcollective/data.rb 31 def self.method_missing(method, *args) 32 super unless PluginManager.include?(pluginname(method)) 33 34 PluginManager[pluginname(method)].lookup(args.first) 35 end
pluginname(plugin)
click to toggle source
# File lib/mcollective/data.rb 22 def self.pluginname(plugin) 23 plugin.to_s =~ /_data$/i ? plugin.to_s.downcase : "%s_data" % plugin.to_s.downcase 24 end