3 autoload :Base, "mcollective/data/base"
4 autoload :Result, "mcollective/data/result"
6 def self.load_data_sources
7 PluginManager.find_and_load("data")
9 PluginManager.grep(/_data$/).each do |plugin|
11 unless PluginManager[plugin].class.activate?
12 Log.debug("Disabling data plugin %s due to plugin activation policy" % plugin)
13 PluginManager.delete(plugin)
16 Log.debug("Disabling data plugin %s due to exception #{e.class}: #{e}" % plugin)
17 PluginManager.delete(plugin)
22 def self.pluginname(plugin)
23 plugin.to_s =~ /_data$/i ? plugin.to_s.downcase : "%s_data" % plugin.to_s.downcase
27 PluginManager[pluginname(plugin)]
30 # Data.package("httpd").architecture
31 def self.method_missing(method, *args)
32 super unless PluginManager.include?(pluginname(method))
34 PluginManager[pluginname(method)].lookup(args.first)
38 DDL.new(pluginname(plugin), :data)
41 def self.ddl_validate(ddl, argument)
42 name = ddl.meta[:name]
43 query = ddl.entities[:data]
45 DDL.validation_fail!(:PLMC31, "No dataquery has been defined in the DDL for data plugin '%{plugin}'", :error, :plugin => name) unless query
47 input = query.fetch(:input, {})
48 output = query.fetch(:output, {})
50 DDL.validation_fail!(:PLMC32, "No output has been defined in the DDL for data plugin %{plugin}", :error, :plugin => name) if output.keys.empty?
53 return true if argument.nil? && input[:query][:optional]
55 ddl.validate_input_argument(input, :query, argument)
57 DDL.validation_fail!(:PLMC33, "No data plugin argument was declared in the '%{plugin}' DDL but an input was supplied", :error, :plugin => name) if argument
62 def self.ddl_has_output?(ddl, output)
63 ddl.entities[:data][:output].include?(output.to_sym) rescue false
66 # For an input where the DDL requests a boolean or some number
67 # this will convert the input to the right type where possible
68 # else just returns the origin input unedited
70 # if anything here goes wrong just return the input value
71 # this is not really the end of the world or anything since
72 # all that will happen is that DDL validation will fail and
73 # the user will get an error, no need to be too defensive here
74 def self.ddl_transform_input(ddl, input)
76 type = ddl.entities[:data][:input][:query][:type]
80 return DDL.string_to_boolean(input)
82 when :number, :integer, :float
83 return DDL.string_to_number(input)