Class: MCollective::Discovery

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/discovery.rb,
lib/mcollective/discovery/mc.rb,
lib/mcollective/discovery/delegate.rb

Defined Under Namespace

Classes: Delegate, Mc

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Discovery

Returns a new instance of Discovery.



3
4
5
# File 'lib/mcollective/discovery.rb', line 3

def initialize(client)
  @client = client
end

Instance Method Details

#check_capabilities(filter) ⇒ Object



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

def check_capabilities(filter)
  true
end

#ddlObject



41
42
43
44
45
46
47
48
49
# File 'lib/mcollective/discovery.rb', line 41

def ddl
  @ddl ||= DDL.new(discovery_method, :discovery)

  # if the discovery method got changed we might have an old DDL cached
  # this will detect that and reread the correct DDL from disk
  @ddl = DDL.new(discovery_method, :discovery) unless @ddl.meta[:name] == discovery_method

  @ddl
end

#discover(filter, timeout, limit, client) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mcollective/discovery.rb', line 64

def discover(filter, timeout, limit, client)
  raise "Limit has to be an integer" unless limit.is_a?(Integer)

  discovered = discovery_class.discover(filter, discovery_timeout(timeout, filter), limit, client)

  if limit > 0
    discovered[0, limit]
  else
    discovered
  end
end

#discovery_classObject



33
34
35
# File 'lib/mcollective/discovery.rb', line 33

def discovery_class
  Delegate
end

#discovery_methodObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mcollective/discovery.rb', line 19

def discovery_method
  if @client.options[:discovery_method]
    method = @client.options[:discovery_method]
  else
    method = Config.instance.default_discovery_method
  end

  raise "Unknown discovery method %s" % method unless has_method?(method)

  raise "Custom discovery methods require direct addressing mode" if method != "mc" && !Config.instance.direct_addressing

  method
end

#discovery_timeout(timeout, filter) ⇒ Object



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

def discovery_timeout(timeout, filter)
  timeout || ddl.meta[:timeout]
end

#find_known_methodsObject



7
8
9
# File 'lib/mcollective/discovery.rb', line 7

def find_known_methods
  ["broadcast", "mc", "inventory", "flatfile", "external", "choria", "file"]
end

#force_direct_mode?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/mcollective/discovery.rb', line 15

def force_direct_mode?
  true
end

#force_discovery_method_by_filter(filter) ⇒ Object

checks if compound filters are used and then forces the ‘mc’ discovery plugin



52
53
54
# File 'lib/mcollective/discovery.rb', line 52

def force_discovery_method_by_filter(filter)
  false
end

#has_method?(method) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mcollective/discovery.rb', line 11

def has_method?(method)
  find_known_methods.include?(method)
end

#timeout_for_compound_filter(compound_filter) ⇒ Object



56
57
58
# File 'lib/mcollective/discovery.rb', line 56

def timeout_for_compound_filter(compound_filter)
  0
end