Sha256: de9d6e3365cf6d3fb2eced4293342f8445729a2bd365cc56bd367cec01c13f56

Contents?: true

Size: 1.45 KB

Versions: 50

Compression:

Stored size: 1.45 KB

Contents

module MCollective
  module Data
    class Fact_data<Base
      query do |path|
        parts = path.split /\./
        walk_path(parts)
      end

      private

      def walk_path(path)
        # Set up results as though we didn't find the value
        result[:exists] = false
        result[:value] = false
        result[:value_encoding] = false

        facts = PluginManager['facts_plugin'].get_facts

        path.each do |level|
          case facts
          when Array
            level = Integer(level)
            if level >= facts.size
              # array index out would be out of bounds, so we don't have the value
              return
            end
          when Hash
            if !facts.include?(level)
              # we don't have the key for the next level, so give up
              return
            end
          else
            # this isn't a container data type, so we can't walk into it
            return
          end

          facts = facts[level]
        end

        result[:exists] = true
        case facts
        when Array, Hash
          # Currently data plugins cannot return structured data, so until
          # this is fixed flatten the data with json and flag that we have
          # munged the data
          result[:value] = facts.to_json
          result[:value_encoding] = 'application/json'
        else
          result[:value] = facts
          result[:value_encoding] = 'text/plain'
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 3 rubygems

Version Path
mcollective-client-2.11.3 lib/mcollective/data/fact_data.rb
mcollective-client-2.11.2 lib/mcollective/data/fact_data.rb
mcollective-client-2.11.1 lib/mcollective/data/fact_data.rb
mcollective-client-2.11.0 lib/mcollective/data/fact_data.rb
mcollective-client-2.10.4 lib/mcollective/data/fact_data.rb
mcollective-client-2.10.3 lib/mcollective/data/fact_data.rb
mcollective-client-2.10.2 lib/mcollective/data/fact_data.rb
mcollective-client-2.10.1 lib/mcollective/data/fact_data.rb
mcollective-client-2.10.0 lib/mcollective/data/fact_data.rb
mcollective-client-2.8.7 lib/mcollective/data/fact_data.rb
mcollective-client-2.8.5 lib/mcollective/data/fact_data.rb
mcollective-client-2.8.8 lib/mcollective/data/fact_data.rb
mcollective-client-2.8.6 lib/mcollective/data/fact_data.rb
mcollective-client-2.9.1 lib/mcollective/data/fact_data.rb
mcollective-client-2.9.0 lib/mcollective/data/fact_data.rb
mcollective-client-2.8.9 lib/mcollective/data/fact_data.rb
dtk-node-agent-0.7.7 mcollective_additions/plugins/v2.2/data/fact_data.rb
dtk-node-agent-0.7.6 mcollective_additions/plugins/v2.2/data/fact_data.rb
dtk-node-agent-0.7.5 mcollective_additions/plugins/v2.2/data/fact_data.rb
mcollective-client-2.8.4 lib/mcollective/data/fact_data.rb