Sha256: 0fd614a3a83070ce3d9cbb83ce706c04d4b3fd942dda0b2cfdfe0d0cecabaf79

Contents?: true

Size: 1.99 KB

Versions: 41

Compression:

Stored size: 1.99 KB

Contents

module Puppet
  class Resource
    class Status
      include Puppet::Util::Tagging
      include Puppet::Util::Logging

      attr_accessor :resource, :node, :file, :line, :current_values, :status, :evaluation_time

      STATES = [:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled]
      attr_accessor *STATES

      attr_reader :source_description, :default_log_level, :time, :resource
      attr_reader :change_count, :out_of_sync_count, :resource_type, :title

      YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title @skipped @failed}

      # Provide a boolean method for each of the states.
      STATES.each do |attr|
        define_method("#{attr}?") do
          !! send(attr)
        end
      end

      def <<(event)
        add_event(event)
        self
      end

      def add_event(event)
        @events << event
        if event.status == 'failure'
          self.failed = true
        elsif event.status == 'success'
          @change_count += 1
          @changed = true
        end
        if event.status != 'audit'
          @out_of_sync_count += 1
          @out_of_sync = true
        end
      end

      def events
        @events
      end

      def initialize(resource)
        @source_description = resource.path
        @resource = resource.to_s
        @change_count = 0
        @out_of_sync_count = 0
        @changed = false
        @out_of_sync = false
        @skipped = false
        @failed = false

        [:file, :line].each do |attr|
          send(attr.to_s + "=", resource.send(attr))
        end

        tag(*resource.tags)
        @time = Time.now
        @events = []
        @resource_type = resource.type.to_s.capitalize
        @title = resource.title
      end

      def to_yaml_properties
        (YAML_ATTRIBUTES & instance_variables).sort
      end

      private

      def log_source
        source_description
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 3 rubygems

Version Path
puppet-2.6.18 lib/puppet/resource/status.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/resource/status.rb
puppet-2.7.19 lib/puppet/resource/status.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/resource/status.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/resource/status.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/resource/status.rb
puppet-2.7.18 lib/puppet/resource/status.rb
puppet-2.6.17 lib/puppet/resource/status.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/resource/status.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/resource/status.rb
puppet-2.7.17 lib/puppet/resource/status.rb
puppet-2.7.16 lib/puppet/resource/status.rb
puppet-2.7.14 lib/puppet/resource/status.rb
puppet-2.6.16 lib/puppet/resource/status.rb
puppet-2.7.13 lib/puppet/resource/status.rb
puppet-2.6.15 lib/puppet/resource/status.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/resource/status.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/resource/status.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/resource/status.rb
puppet-2.7.12 lib/puppet/resource/status.rb