Sha256: 9bda35312aeea37a31efe71f24cad873323455b9eaa226cf377cff8df56fd3ff

Contents?: true

Size: 1.49 KB

Versions: 50

Compression:

Stored size: 1.49 KB

Contents

# 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).each do |host|
          host = host.chomp.strip
          if host.empty? || host.match(/^#/)
            next
          end
          raise 'Identities can only match /^[\w\.\-]+$/' unless host.match(/^[\w\.\-]+$/)
          hosts << host
        end

        # this plugin only supports identity filters, do regex matches etc against
        # the list found in the flatfile
        if !(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

Version data entries

50 entries across 50 versions & 3 rubygems

Version Path
choria-mcorpc-support-2.22.1 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.22.0 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.21.1 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.21.0 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.8 lib/mcollective/discovery/flatfile.rb
mcollective-client-2.12.5 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.7 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.6 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.5 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.4 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.3 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.2 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-2.20.0 lib/mcollective/discovery/flatfile.rb
choria-mcorpc-support-0.0.1 lib/mcollective/discovery/flatfile.rb
mcollective-client-2.12.4 lib/mcollective/discovery/flatfile.rb
mcollective-client-2.12.3 lib/mcollective/discovery/flatfile.rb
mcollective-client-2.12.1 lib/mcollective/discovery/flatfile.rb
mcollective-client-2.12.0 lib/mcollective/discovery/flatfile.rb
mcollective-client-2.10.6 lib/mcollective/discovery/flatfile.rb
mcollective-client-2.11.4 lib/mcollective/discovery/flatfile.rb