Parent

Class/Module Index [+]

Quicksearch

MCollective::Discovery

Public Instance Methods

check_capabilities(filter) click to toggle source

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

# 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() click to toggle source
# 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.meta[:name] == discovery_method
    @ddl = DDL.new(discovery_method, :discovery)
  end

  return @ddl
end
discover(filter, timeout, limit) click to toggle source
# File lib/mcollective/discovery.rb, line 96
def discover(filter, timeout, limit)
  raise "Limit has to be an integer" unless limit.is_a?(Fixnum)

  if force_discovery_method_by_filter(filter)
    timeout = ddl.meta[:timeout] + @client.timeout_for_compound_filter(filter["compound"])
  else
    timeout = ddl.meta[:timeout] unless timeout
  end

  check_capabilities(filter)

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

  if limit > 0
    return discovered[0,limit]
  else
    return discovered
  end
end
discovery_class() click to toggle source
# 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() click to toggle source
# File lib/mcollective/discovery.rb, line 21
def discovery_method
  method = "mc"

  if @client.options[:discovery_method]
    method = @client.options[: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
find_known_methods() click to toggle source
# File lib/mcollective/discovery.rb, line 9
def find_known_methods
  PluginManager.find("discovery")
end
force_direct_mode?() click to toggle source
# File lib/mcollective/discovery.rb, line 17
def force_direct_mode?
  discovery_method != "mc"
end
force_discovery_method_by_filter(filter) click to toggle source

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

# 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.options[:discovery_method] = "mc"

      return true
    end
  end

  return false
end
has_method?(method) click to toggle source
# File lib/mcollective/discovery.rb, line 13
def has_method?(method)
  @known_methods.include?(method)
end

Public Class Methods

new(client) click to toggle source
# File lib/mcollective/discovery.rb, line 3
def initialize(client)
  @known_methods = find_known_methods
  @default_method = Config.instance.default_discovery_method
  @client = client
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.