Class MCollective::Discovery
In: lib/mcollective/discovery.rb
Parent: Object

Methods

Public Class methods

[Source]

   # File lib/mcollective/discovery.rb, line 3
3:     def initialize(client)
4:       @known_methods = find_known_methods
5:       @default_method = Config.instance.default_discovery_method
6:       @client = client
7:     end

Public Instance methods

Agent filters are always present no matter what, so we cant raise an error if the capabilities suggest the discovery method cant do agents we just have to rely on the discovery plugin to not do stupid things in the presense of a agent filter

[Source]

    # File lib/mcollective/discovery.rb, line 62
62:     def check_capabilities(filter)
63:       capabilities = ddl.discovery_interface[:capabilities]
64: 
65:       unless capabilities.include?(:classes)
66:         raise "Cannot use class filters while using the '%s' discovery method" % discovery_method unless filter["cf_class"].empty?
67:       end
68: 
69:       unless capabilities.include?(:facts)
70:         raise "Cannot use fact filters while using the '%s' discovery method" % discovery_method unless filter["fact"].empty?
71:       end
72: 
73:       unless capabilities.include?(:identity)
74:         raise "Cannot use identity filters while using the '%s' discovery method" % discovery_method unless filter["identity"].empty?
75:       end
76: 
77:       unless capabilities.include?(:compound)
78:         raise "Cannot use compound filters while using the '%s' discovery method" % discovery_method unless filter["compound"].empty?
79:       end
80:     end

[Source]

    # File lib/mcollective/discovery.rb, line 47
47:     def ddl
48:       @ddl ||= DDL.new(discovery_method, :discovery)
49: 
50:       # if the discovery method got changed we might have an old DDL cached
51:       # this will detect that and reread the correct DDL from disk
52:       unless @ddl.meta[:name] == discovery_method
53:         @ddl = DDL.new(discovery_method, :discovery)
54:       end
55: 
56:       return @ddl
57:     end

[Source]

     # File lib/mcollective/discovery.rb, line 96
 96:     def discover(filter, timeout, limit)
 97:       raise "Limit has to be an integer" unless limit.is_a?(Fixnum)
 98: 
 99:       if force_discovery_method_by_filter(filter)
100:         timeout = ddl.meta[:timeout] + @client.timeout_for_compound_filter(filter["compound"])
101:       else
102:         timeout = ddl.meta[:timeout] unless timeout
103:       end
104: 
105:       check_capabilities(filter)
106: 
107:       discovered = discovery_class.discover(filter, timeout, limit, @client)
108: 
109:       if limit > 0
110:         return discovered[0,limit]
111:       else
112:         return discovered
113:       end
114:     end

[Source]

    # File lib/mcollective/discovery.rb, line 39
39:     def discovery_class
40:       method = discovery_method.capitalize
41: 
42:       PluginManager.loadclass("MCollective::Discovery::#{method}") unless self.class.const_defined?(method)
43: 
44:       self.class.const_get(method)
45:     end

[Source]

    # File lib/mcollective/discovery.rb, line 21
21:     def discovery_method
22:       method = "mc"
23: 
24:       if @client.options[:discovery_method]
25:         method = @client.options[:discovery_method]
26:       else
27:         method = @default_method
28:       end
29: 
30:       raise "Unknown discovery method %s" % method unless has_method?(method)
31: 
32:       unless method == "mc"
33:         raise "Custom discovery methods require direct addressing mode" unless Config.instance.direct_addressing
34:       end
35: 
36:       return method
37:     end

[Source]

    # File lib/mcollective/discovery.rb, line 9
 9:     def find_known_methods
10:       PluginManager.find("discovery")
11:     end

[Source]

    # File lib/mcollective/discovery.rb, line 17
17:     def force_direct_mode?
18:       discovery_method != "mc"
19:     end

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

[Source]

    # File lib/mcollective/discovery.rb, line 83
83:     def force_discovery_method_by_filter(filter)
84:       unless discovery_method == "mc"
85:         unless filter["compound"].empty?
86:           Log.info "Switching to mc discovery method because compound filters are used"
87:           @client.options[:discovery_method] = "mc"
88: 
89:           return true
90:         end
91:       end
92: 
93:       return false
94:     end

[Source]

    # File lib/mcollective/discovery.rb, line 13
13:     def has_method?(method)
14:       @known_methods.include?(method)
15:     end

[Validate]