Class: MCollective::Discovery::Mc

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

Class Method Summary collapse

Class Method Details

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mcollective/discovery/mc.rb', line 4

def self.discover(filter, timeout, limit, client)
  begin
    hosts = []
    Timeout.timeout(timeout) do
      reqid = client.sendreq("ping", "discovery", filter)
      Log.debug("Waiting #{timeout} seconds for discovery replies to request #{reqid}")

      loop do
        reply = client.receive(reqid)
        Log.debug("Got discovery reply from #{reply.payload[:senderid]}")
        hosts << reply.payload[:senderid]

        return hosts if limit > 0 && hosts.size == limit
      end
    end
  rescue Timeout::Error => e
  rescue Exception => e
    raise
  ensure
    client.unsubscribe("discovery", :reply)
  end

  hosts
end