Class: Puppet::Resource::Status

Inherits:
Object
  • Object
show all
Includes:
Network::FormatSupport, Util::Logging, Util::Tagging
Defined in:
lib/puppet/resource/status.rb

Overview

API:

  • public

Constant Summary collapse

STATES =

API:

  • public

[:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled]
YAML_ATTRIBUTES =

API:

  • public

%w{@resource @file @line @evaluation_time @change_count
                   @out_of_sync_count @tags @time @events @out_of_sync
                   @changed @resource_type @title @skipped @failed
                   @containment_path}.
map(&:to_sym)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Network::FormatSupport

included, #mime, #render, #support_format?, #to_msgpack

Methods included from Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #send_log

Methods included from Util::Tagging

#tag, #tagged?, #tags, #tags=

Constructor Details

#initialize(resource) ⇒ Status

Returns a new instance of Status.

API:

  • public



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/puppet/resource/status.rb', line 73

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

  @file = resource.file
  @line = resource.line

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

Instance Attribute Details

#change_countObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def change_count
  @change_count
end

#containment_pathObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def containment_path
  @containment_path
end

#current_valuesObject

API:

  • public



11
12
13
# File 'lib/puppet/resource/status.rb', line 11

def current_values
  @current_values
end

#default_log_levelObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def default_log_level
  @default_log_level
end

#evaluation_timeObject

API:

  • public



11
12
13
# File 'lib/puppet/resource/status.rb', line 11

def evaluation_time
  @evaluation_time
end

#fileObject

API:

  • public



11
12
13
# File 'lib/puppet/resource/status.rb', line 11

def file
  @file
end

#lineObject

API:

  • public



11
12
13
# File 'lib/puppet/resource/status.rb', line 11

def line
  @line
end

#nodeObject

API:

  • public



11
12
13
# File 'lib/puppet/resource/status.rb', line 11

def node
  @node
end

#out_of_sync_countObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def out_of_sync_count
  @out_of_sync_count
end

#resourceObject

API:

  • public



11
12
13
# File 'lib/puppet/resource/status.rb', line 11

def resource
  @resource
end

#resource_typeObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def resource_type
  @resource_type
end

#source_descriptionObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def source_description
  @source_description
end

#statusObject

API:

  • public



11
12
13
# File 'lib/puppet/resource/status.rb', line 11

def status
  @status
end

#timeObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def time
  @time
end

#titleObject (readonly)

API:

  • public



16
17
18
# File 'lib/puppet/resource/status.rb', line 16

def title
  @title
end

Class Method Details

.from_pson(data) ⇒ Object

API:

  • public



27
28
29
30
31
# File 'lib/puppet/resource/status.rb', line 27

def self.from_pson(data)
  obj = self.allocate
  obj.initialize_from_hash(data)
  obj
end

Instance Method Details

#<<(event) ⇒ Object

API:

  • public



40
41
42
43
# File 'lib/puppet/resource/status.rb', line 40

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

#add_event(event) ⇒ Object

API:

  • public



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/resource/status.rb', line 45

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

#eventsObject

API:

  • public



59
60
61
# File 'lib/puppet/resource/status.rb', line 59

def events
  @events
end

#failed_because(detail) ⇒ Object

API:

  • public



63
64
65
66
67
68
69
70
71
# File 'lib/puppet/resource/status.rb', line 63

def failed_because(detail)
  @real_resource.log_exception(detail, "Could not evaluate: #{detail}")
  failed = true
  # There's a contract (implicit unfortunately) that a status of failed
  # will always be accompanied by an event with some explanatory power.  This
  # is useful for reporting/diagnostics/etc.  So synthesize an event here
  # with the exception detail as the message.
  add_event(@real_resource.event(:name => :resource_error, :status => "failure", :message => detail.to_s))
end

#initialize_from_hash(data) ⇒ Object

API:

  • public



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/puppet/resource/status.rb', line 95

def initialize_from_hash(data)
  @resource_type = data['resource_type']
  @title = data['title']
  @resource = data['resource']
  @containment_path = data['containment_path']
  @file = data['file']
  @line = data['line']
  @evaluation_time = data['evaluation_time']
  @change_count = data['change_count']
  @out_of_sync_count = data['out_of_sync_count']
  @tags = Puppet::Util::TagSet.new(data['tags'])
  @time = data['time']
  @time = Time.parse(@time) if @time.is_a? String
  @out_of_sync = data['out_of_sync']
  @changed = data['changed']
  @skipped = data['skipped']
  @failed = data['failed']

  @events = data['events'].map do |event|
    Puppet::Transaction::Event.from_pson(event)
  end
end

#to_data_hashObject

API:

  • public



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/puppet/resource/status.rb', line 118

def to_data_hash
  {
    'title' => @title,
    'file' => @file,
    'line' => @line,
    'resource' => @resource,
    'resource_type' => @resource_type,
    'containment_path' => @containment_path,
    'evaluation_time' => @evaluation_time,
    'tags' => @tags,
    'time' => @time.iso8601(9),
    'failed' => @failed,
    'changed' => @changed,
    'out_of_sync' => @out_of_sync,
    'skipped' => @skipped,
    'change_count' => @change_count,
    'out_of_sync_count' => @out_of_sync_count,
    'events' => @events,
  }
end

#to_pson(*args) ⇒ Object

API:

  • public



139
140
141
# File 'lib/puppet/resource/status.rb', line 139

def to_pson(*args)
  to_data_hash.to_pson(*args)
end

#to_yaml_propertiesObject

API:

  • public



143
144
145
# File 'lib/puppet/resource/status.rb', line 143

def to_yaml_properties
  YAML_ATTRIBUTES & super
end