Module: MCollective::Data

Defined in:
lib/mcollective/data.rb,
lib/mcollective/data/base.rb,
lib/mcollective/data/result.rb,
lib/mcollective/data/fact_data.rb,
lib/mcollective/data/agent_data.rb,
lib/mcollective/data/fstat_data.rb,
lib/mcollective/data/collective_data.rb

Defined Under Namespace

Classes: Agent_data, Base, Collective_data, Fact_data, Fstat_data, Result

Class Method Summary collapse

Class Method Details

.[](plugin) ⇒ Object



26
27
28
# File 'lib/mcollective/data.rb', line 26

def self.[](plugin)
  PluginManager[pluginname(plugin)]
end

.ddl(plugin) ⇒ Object



37
38
39
# File 'lib/mcollective/data.rb', line 37

def self.ddl(plugin)
  DDL.new(pluginname(plugin), :data)
end

.ddl_has_output?(ddl, output) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/mcollective/data.rb', line 62

def self.ddl_has_output?(ddl, output)
  ddl.entities[:data][:output].include?(output.to_sym) rescue false
end

.ddl_transform_input(ddl, input) ⇒ Object

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mcollective/data.rb', line 74

def self.ddl_transform_input(ddl, input)
  begin
    type = ddl.entities[:data][:input][:query][:type]

    case type
      when :boolean
        return DDL.string_to_boolean(input)

      when :number, :integer, :float
        return DDL.string_to_number(input)
    end
  rescue
  end

  return input
end

.ddl_validate(ddl, argument) ⇒ Object

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mcollective/data.rb', line 41

def self.ddl_validate(ddl, argument)
  name = ddl.meta[:name]
  query = ddl.entities[:data]

  raise DDLValidationError, "No dataquery has been defined in the DDL for data plugin #{name}" unless query

  input = query.fetch(:input, {})
  output = query.fetch(:output, {})

  raise DDLValidationError, "No output has been defined in the DDL for data plugin #{name}" if output.keys.empty?

  if input[:query]
    return true if argument.nil? && input[:query][:optional]

    ddl.validate_input_argument(input, :query, argument)
  else
    raise("No data plugin argument was declared in the %s DDL but an input was supplied" % name) if argument
    return true
  end
end

.load_data_sourcesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mcollective/data.rb', line 6

def self.load_data_sources
  PluginManager.find_and_load("data")

  PluginManager.grep(/_data$/).each do |plugin|
    begin
      unless PluginManager[plugin].class.activate?
        Log.debug("Disabling data plugin %s due to plugin activation policy" % plugin)
        PluginManager.delete(plugin)
      end
    rescue Exception => e
      Log.debug("Disabling data plugin %s due to exception #{e.class}: #{e}" % plugin)
      PluginManager.delete(plugin)
    end
  end
end

.method_missing(method, *args) ⇒ Object

Data.package(“httpd”).architecture



31
32
33
34
35
# File 'lib/mcollective/data.rb', line 31

def self.method_missing(method, *args)
  super unless PluginManager.include?(pluginname(method))

  PluginManager[pluginname(method)].lookup(args.first)
end

.pluginname(plugin) ⇒ Object



22
23
24
# File 'lib/mcollective/data.rb', line 22

def self.pluginname(plugin)
  plugin.to_s =~ /_data$/i ? plugin.to_s.downcase : "%s_data" % plugin.to_s.downcase
end