Class: MCollective::Discovery
- Inherits:
-
Object
- Object
- MCollective::Discovery
- Defined in:
- lib/mcollective/discovery.rb
Instance Method Summary collapse
-
#check_capabilities(filter) ⇒ Object
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.
- #ddl ⇒ Object
- #discover(filter, timeout, limit) ⇒ Object
- #discovery_class ⇒ Object
- #discovery_method ⇒ Object
- #discovery_timeout(timeout, filter) ⇒ Object
- #find_known_methods ⇒ Object
- #force_direct_mode? ⇒ Boolean
-
#force_discovery_method_by_filter(filter) ⇒ Object
checks if compound filters are used and then forces the ‘mc’ discovery plugin.
- #has_method?(method) ⇒ Boolean
-
#initialize(client) ⇒ Discovery
constructor
A new instance of Discovery.
-
#timeout_for_compound_filter(compound_filter) ⇒ Object
if a compound filter is specified and it has any function then we read the DDL for each of those plugins and sum up the timeout declared in the DDL.
Constructor Details
Instance Method Details
#check_capabilities(filter) ⇒ Object
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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mcollective/discovery.rb', line 62 def check_capabilities(filter) capabilities = ddl.discovery_interface[:capabilities] unless capabilities.include?(:classes) raise "Cannot use class filters while using the '%s' discovery method" % discovery_method unless filter["cf_class"].empty? end unless capabilities.include?(:facts) raise "Cannot use fact filters while using the '%s' discovery method" % discovery_method unless filter["fact"].empty? end unless capabilities.include?(:identity) raise "Cannot use identity filters while using the '%s' discovery method" % discovery_method unless filter["identity"].empty? end unless capabilities.include?(:compound) raise "Cannot use compound filters while using the '%s' discovery method" % discovery_method unless filter["compound"].empty? end end |
#ddl ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mcollective/discovery.rb', line 47 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 unless @ddl.[:name] == discovery_method @ddl = DDL.new(discovery_method, :discovery) end return @ddl end |
#discover(filter, timeout, limit) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/mcollective/discovery.rb', line 127 def discover(filter, timeout, limit) raise "Limit has to be an integer" unless limit.is_a?(Fixnum) force_discovery_method_by_filter(filter) check_capabilities(filter) discovered = discovery_class.discover(filter, discovery_timeout(timeout, filter), limit, @client) if limit > 0 return discovered[0,limit] else return discovered end end |
#discovery_class ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mcollective/discovery.rb', line 39 def discovery_class method = discovery_method.capitalize PluginManager.loadclass("MCollective::Discovery::#{method}") unless self.class.const_defined?(method) self.class.const_get(method) end |
#discovery_method ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mcollective/discovery.rb', line 21 def discovery_method method = "mc" if @client.[:discovery_method] method = @client.[:discovery_method] else method = @default_method end raise "Unknown discovery method %s" % method unless has_method?(method) unless method == "mc" raise "Custom discovery methods require direct addressing mode" unless Config.instance.direct_addressing end return method end |
#discovery_timeout(timeout, filter) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/mcollective/discovery.rb', line 117 def discovery_timeout(timeout, filter) timeout = ddl.[:timeout] unless timeout unless (filter["compound"] && filter["compound"].empty?) timeout + timeout_for_compound_filter(filter["compound"]) else timeout end end |
#find_known_methods ⇒ Object
9 10 11 |
# File 'lib/mcollective/discovery.rb', line 9 def find_known_methods PluginManager.find("discovery") end |
#force_direct_mode? ⇒ Boolean
17 18 19 |
# File 'lib/mcollective/discovery.rb', line 17 def force_direct_mode? discovery_method != "mc" end |
#force_discovery_method_by_filter(filter) ⇒ Object
checks if compound filters are used and then forces the ‘mc’ discovery plugin
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mcollective/discovery.rb', line 83 def force_discovery_method_by_filter(filter) unless discovery_method == "mc" unless filter["compound"].empty? Log.info "Switching to mc discovery method because compound filters are used" @client.[:discovery_method] = "mc" return true end end return false end |
#has_method?(method) ⇒ Boolean
13 14 15 |
# File 'lib/mcollective/discovery.rb', line 13 def has_method?(method) @known_methods.include?(method) end |
#timeout_for_compound_filter(compound_filter) ⇒ Object
if a compound filter is specified and it has any function then we read the DDL for each of those plugins and sum up the timeout declared in the DDL
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mcollective/discovery.rb', line 99 def timeout_for_compound_filter(compound_filter) return 0 if compound_filter.nil? || compound_filter.empty? timeout = 0 compound_filter.each do |filter| filter.each do |statement| if statement["fstatement"] pluginname = Data.pluginname(statement["fstatement"]["name"]) ddl = DDL.new(pluginname, :data) timeout += ddl.[:timeout] end end end timeout end |