def discover(flags={})
flags.keys.each do |key|
raise "Unknown option #{key} passed to discover" unless [:verbose, :hosts, :nodes, :json].include?(key)
end
flags.include?(:verbose) ? verbose = flags[:verbose] : verbose = @verbose
verbose = false unless @output_format == :console
flags[:nodes] = flags.delete(:hosts) if flags.include?(:hosts)
reset if flags[:nodes] || flags[:json]
unless @discovered_agents
if flags[:nodes] || flags[:json]
raise "Can only supply discovery data if direct_addressing is enabled" unless Config.instance.direct_addressing
hosts = []
if flags[:nodes]
hosts = Helpers.extract_hosts_from_array(flags[:nodes])
elsif flags[:json]
hosts = Helpers.extract_hosts_from_json(flags[:json])
end
raise "Could not find any hosts in discovery data provided" if hosts.empty?
@discovered_agents = hosts
@force_direct_request = true
else
identity_filter_discovery_optimization
end
end
unless @discovered_agents
@stats.time_discovery :start
@client.options = options
@client.discoverer.force_discovery_method_by_filter(options[:filter])
if verbose
actual_timeout = @client.discoverer.discovery_timeout(discovery_timeout, options[:filter])
if actual_timeout > 0
@stderr.print("Discovering hosts using the %s method for %d second(s) .... " % [@client.discoverer.discovery_method, actual_timeout])
else
@stderr.print("Discovering hosts using the %s method .... " % [@client.discoverer.discovery_method])
end
end
filter = @filter.merge({'collective' => @collective})
if @limit_method == :first and @limit_targets.is_a?(Fixnum)
@discovered_agents = @client.discover(filter, discovery_timeout, @limit_targets)
else
@discovered_agents = @client.discover(filter, discovery_timeout)
end
@stderr.puts(@discovered_agents.size) if verbose
@force_direct_request = @client.discoverer.force_direct_mode?
@stats.time_discovery :end
end
@stats.discovered_agents(@discovered_agents)
RPC.discovered(@discovered_agents)
@discovered_agents
end