X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=plugins%2Fmcollective%2Fdiscovery%2Fmc.rb;fp=plugins%2Fmcollective%2Fdiscovery%2Fmc.rb;h=efd1d828389fbf34a3d666d0b872c529837a94c9;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/plugins/mcollective/discovery/mc.rb b/plugins/mcollective/discovery/mc.rb new file mode 100644 index 0000000..efd1d82 --- /dev/null +++ b/plugins/mcollective/discovery/mc.rb @@ -0,0 +1,30 @@ +module MCollective + class Discovery + class Mc + 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 + end + end +end