Class: Puppet::Resource::Status

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

Constant Summary collapse

STATES =
[:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled]
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}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #send_log

Methods included from Util::Tagging

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

Constructor Details

#initialize(resource) ⇒ Status

Returns a new instance of Status.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/puppet/resource/status.rb', line 54

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

Instance Attribute Details

#change_countObject (readonly)

Returns the value of attribute change_count.



13
14
15
# File 'lib/puppet/resource/status.rb', line 13

def change_count
  @change_count
end

#current_valuesObject

Returns the value of attribute current_values.



7
8
9
# File 'lib/puppet/resource/status.rb', line 7

def current_values
  @current_values
end

#default_log_levelObject (readonly)

Returns the value of attribute default_log_level.



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

def default_log_level
  @default_log_level
end

#evaluation_timeObject

Returns the value of attribute evaluation_time.



7
8
9
# File 'lib/puppet/resource/status.rb', line 7

def evaluation_time
  @evaluation_time
end

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/puppet/resource/status.rb', line 7

def file
  @file
end

#lineObject

Returns the value of attribute line.



7
8
9
# File 'lib/puppet/resource/status.rb', line 7

def line
  @line
end

#nodeObject

Returns the value of attribute node.



7
8
9
# File 'lib/puppet/resource/status.rb', line 7

def node
  @node
end

#out_of_sync_countObject (readonly)

Returns the value of attribute out_of_sync_count.



13
14
15
# File 'lib/puppet/resource/status.rb', line 13

def out_of_sync_count
  @out_of_sync_count
end

#resourceObject

Returns the value of attribute resource.



7
8
9
# File 'lib/puppet/resource/status.rb', line 7

def resource
  @resource
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



13
14
15
# File 'lib/puppet/resource/status.rb', line 13

def resource_type
  @resource_type
end

#source_descriptionObject (readonly)

Returns the value of attribute source_description.



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

def source_description
  @source_description
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/puppet/resource/status.rb', line 7

def status
  @status
end

#timeObject (readonly)

Returns the value of attribute time.



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

def time
  @time
end

#titleObject (readonly)

Returns the value of attribute title.



13
14
15
# File 'lib/puppet/resource/status.rb', line 13

def title
  @title
end

Class Method Details

.from_pson(data) ⇒ Object



18
19
20
21
22
# File 'lib/puppet/resource/status.rb', line 18

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

Instance Method Details

#<<(event) ⇒ Object



31
32
33
34
# File 'lib/puppet/resource/status.rb', line 31

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

#add_event(event) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet/resource/status.rb', line 36

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



50
51
52
# File 'lib/puppet/resource/status.rb', line 50

def events
  @events
end

#initialize_from_hash(data) ⇒ Object



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

def initialize_from_hash(data)
  @resource_type = data['resource_type']
  @title = data['title']
  @resource = data['resource']
  @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 = data['tags']
  @time = data['time']
  @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_yaml_propertiesObject



96
97
98
# File 'lib/puppet/resource/status.rb', line 96

def to_yaml_properties
  YAML_ATTRIBUTES & instance_variables
end