Class: MCollective::Data::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/data/base.rb

Direct Known Subclasses

Agent_data, Collective_data, Fact_data, Fstat_data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



13
14
15
16
17
18
19
20
# File 'lib/mcollective/data/base.rb', line 13

def initialize
  @name = self.class.to_s.split("::").last.downcase
  @ddl = DDL.new(@name, :data)
  @result = Result.new(@ddl.dataquery_interface[:output])
  @timeout = @ddl.meta[:timeout] || 1

  startup_hook
end

Instance Attribute Details

#ddlObject (readonly)

Returns the value of attribute ddl.



4
5
6
# File 'lib/mcollective/data/base.rb', line 4

def ddl
  @ddl
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/mcollective/data/base.rb', line 4

def name
  @name
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/mcollective/data/base.rb', line 4

def result
  @result
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



4
5
6
# File 'lib/mcollective/data/base.rb', line 4

def timeout
  @timeout
end

Class Method Details

.activate?Boolean

Always be active unless a specific block is given with activate_when

Returns:

  • (Boolean)


60
61
62
# File 'lib/mcollective/data/base.rb', line 60

def self.activate?
  return true
end

.activate_when(&block) ⇒ Object

activate_when do

file.exist?("/usr/bin/puppet")

end



53
54
55
56
57
# File 'lib/mcollective/data/base.rb', line 53

def self.activate_when(&block)
  (class << self; self; end).instance_eval do
    define_method("activate?", &block)
  end
end

.inherited(klass) ⇒ Object

Register plugins that inherits base



7
8
9
10
11
# File 'lib/mcollective/data/base.rb', line 7

def self.inherited(klass)
  type = klass.to_s.split("::").last.downcase

  PluginManager << {:type => type, :class => klass.to_s, :single_instance => false}
end

.query(&block) ⇒ Object



42
43
44
# File 'lib/mcollective/data/base.rb', line 42

def self.query(&block)
  self.module_eval { define_method("query_data", &block) }
end

Instance Method Details

#ddl_validate(what) ⇒ Object



46
47
48
# File 'lib/mcollective/data/base.rb', line 46

def ddl_validate(what)
  Data.ddl_validate(@ddl, what)
end

#lookup(what) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mcollective/data/base.rb', line 22

def lookup(what)
  ddl_validate(what)

  Log.debug("Doing data query %s for '%s'" % [ @name, what ])

  Timeout::timeout(@timeout) do
    query_data(what)
  end

  @result
rescue Timeout::Error
  # Timeout::Error is a inherited from Interrupt which seems a really
  # strange choice, making it an equivelant of ^C and such.  Catch it
  # and raise something less critical that will not the runner to just
  # give up the ghost
  msg = "Data plugin %s timed out on query '%s'" % [@name, what]
  Log.error(msg)
  raise MsgTTLExpired, msg
end

#startup_hookObject



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

def startup_hook;end