X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fmcollective%2Fdiscovery%2Fflatfile.rb;fp=plugins%2Fmcollective%2Fdiscovery%2Fflatfile.rb;h=7ce9db7b42dca6bdba8a83afe7e09c9b1c5afa0c;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/plugins/mcollective/discovery/flatfile.rb b/plugins/mcollective/discovery/flatfile.rb new file mode 100644 index 0000000..7ce9db7 --- /dev/null +++ b/plugins/mcollective/discovery/flatfile.rb @@ -0,0 +1,40 @@ +# discovers against a flatfile instead of the traditional network discovery +# the flat file must have a node name per line which should match identities +# as configured +module MCollective + class Discovery + class Flatfile + def self.discover(filter, timeout, limit=0, client=nil) + unless client.options[:discovery_options].empty? + file = client.options[:discovery_options].first + else + raise "The flatfile discovery method needs a path to a text file" + end + + raise "Cannot read the file %s specified as discovery source" % file unless File.readable?(file) + + discovered = [] + + hosts = File.readlines(file).map{|l| l.chomp} + + # this plugin only supports identity filters, do regex matches etc against + # the list found in the flatfile + unless filter["identity"].empty? + filter["identity"].each do |identity| + identity = Regexp.new(identity.gsub("\/", "")) if identity.match("^/") + + if identity.is_a?(Regexp) + discovered = hosts.grep(identity) + elsif hosts.include?(identity) + discovered << identity + end + end + else + discovered = hosts + end + + discovered + end + end + end +end