Class: Chef::Formatters::MinimalDiff

Inherits:
Formatters::Base
  • Object
show all
Defined in:
lib/minimal-diff-chef-formatter.rb

Overview

Unlike the Formatters::Minimal it shows diff for updated resources.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out, err) ⇒ MinimalDiff

Returns a new instance of MinimalDiff.



26
27
28
29
30
# File 'lib/minimal-diff-chef-formatter.rb', line 26

def initialize(out, err)
  super
  @updated_resources = []
  @updates_by_resource = Hash.new {|h, k| h[k] = []}
end

Instance Attribute Details

#updated_resourcesObject (readonly)

Returns the value of attribute updated_resources.



22
23
24
# File 'lib/minimal-diff-chef-formatter.rb', line 22

def updated_resources
  @updated_resources
end

#updates_by_resourceObject (readonly)

Returns the value of attribute updates_by_resource.



23
24
25
# File 'lib/minimal-diff-chef-formatter.rb', line 23

def updates_by_resource
  @updates_by_resource
end

Instance Method Details

#converge_completeObject

Called when the converge phase is finished.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/minimal-diff-chef-formatter.rb', line 153

def converge_complete
  puts "\n"
  puts "System converged."
  if updated_resources.empty?
    puts "no resources updated"
  else
    puts "\n"
    puts "resources updated this run:"
    updated_resources.each do |resource|
      puts "* #{resource.to_s}"
      updates_by_resource[resource.name].flatten.each do |update|
        puts "  #{update}"
      end
    end
  end
end

#converge_start(run_context) ⇒ Object

Called before convergence starts



148
149
150
# File 'lib/minimal-diff-chef-formatter.rb', line 148

def converge_start(run_context)
  puts "Converging #{run_context.resource_collection.all_resources.size} resources"
end

#cookbook_clean_completeObject

Called when cookbook cleaning is finished.



106
107
# File 'lib/minimal-diff-chef-formatter.rb', line 106

def cookbook_clean_complete
end

#cookbook_clean_startObject

Called before unneeded cookbooks are removed – TODO: Should be called in CookbookVersion.sync_cookbooks



96
97
# File 'lib/minimal-diff-chef-formatter.rb', line 96

def cookbook_clean_start
end

#cookbook_resolution_complete(cookbook_collection) ⇒ Object

Called when the cookbook collection is returned from the server.



90
91
# File 'lib/minimal-diff-chef-formatter.rb', line 90

def cookbook_resolution_complete(cookbook_collection)
end

#cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object

Called when there is an error getting the cookbook collection from the server.



86
87
# File 'lib/minimal-diff-chef-formatter.rb', line 86

def cookbook_resolution_failed(expanded_run_list, exception)
end

#cookbook_resolution_start(expanded_run_list) ⇒ Object

Called before the cookbook collection is fetched from the server.



80
81
82
# File 'lib/minimal-diff-chef-formatter.rb', line 80

def cookbook_resolution_start(expanded_run_list)
  puts "resolving cookbooks for run list: #{expanded_run_list.inspect}"
end

#cookbook_sync_completeObject

Called after all cookbooks have been sync’d.



124
125
126
# File 'lib/minimal-diff-chef-formatter.rb', line 124

def cookbook_sync_complete
  puts "done."
end

#cookbook_sync_start(cookbook_count) ⇒ Object

Called before cookbook sync starts



110
111
112
# File 'lib/minimal-diff-chef-formatter.rb', line 110

def cookbook_sync_start(cookbook_count)
  puts "Synchronizing cookbooks"
end

#file_load_failed(path, exception) ⇒ Object



138
139
140
# File 'lib/minimal-diff-chef-formatter.rb', line 138

def file_load_failed(path, exception)
  super
end

#file_loaded(path) ⇒ Object

Called after a file in a cookbook is loaded.



134
135
136
# File 'lib/minimal-diff-chef-formatter.rb', line 134

def file_loaded(path)
  print '.'
end

#handler_executed(handler) ⇒ Object

Called after an individual handler has run



230
231
# File 'lib/minimal-diff-chef-formatter.rb', line 230

def handler_executed(handler)
end

#handlers_completedObject

Called after all handlers have executed



234
235
# File 'lib/minimal-diff-chef-formatter.rb', line 234

def handlers_completed
end

#handlers_start(handler_count) ⇒ Object

Called before handlers run



226
227
# File 'lib/minimal-diff-chef-formatter.rb', line 226

def handlers_start(handler_count)
end

#library_load_start(file_count) ⇒ Object

Called when cookbook loading starts.



129
130
131
# File 'lib/minimal-diff-chef-formatter.rb', line 129

def library_load_start(file_count)
  puts "Compiling cookbooks"
end

#msg(message) ⇒ Object

An uncategorized message. This supports the case that a user needs to pass output that doesn’t fit into one of the callbacks above. Note that there’s no semantic information about the content or importance of the message. That means that if you’re using this too often, you should add a callback for it.



242
243
# File 'lib/minimal-diff-chef-formatter.rb', line 242

def msg(message)
end

#node_load_completed(node, expanded_run_list, config) ⇒ Object

Default and override attrs from roles have been computed, but not yet applied. Normal attrs from JSON have been added to the node.



76
77
# File 'lib/minimal-diff-chef-formatter.rb', line 76

def node_load_completed(node, expanded_run_list, config)
end

#node_load_failed(node_name, exception, config) ⇒ Object

Failed to load node data from the server



71
72
# File 'lib/minimal-diff-chef-formatter.rb', line 71

def node_load_failed(node_name, exception, config)
end

#node_load_start(node_name, config) ⇒ Object



67
68
# File 'lib/minimal-diff-chef-formatter.rb', line 67

def node_load_start(node_name, config)
end

#ohai_completed(node) ⇒ Object

Called right after ohai runs.



48
49
# File 'lib/minimal-diff-chef-formatter.rb', line 48

def ohai_completed(node)
end

#recipe_load_completeObject

Called when recipes have been loaded.



143
144
145
# File 'lib/minimal-diff-chef-formatter.rb', line 143

def recipe_load_complete
  puts "done."
end

#registration_completedObject



59
60
# File 'lib/minimal-diff-chef-formatter.rb', line 59

def registration_completed
end

#registration_failed(node_name, exception, config) ⇒ Object

Failed to register this client with the server.



63
64
65
# File 'lib/minimal-diff-chef-formatter.rb', line 63

def registration_failed(node_name, exception, config)
  super
end

#registration_start(node_name, config) ⇒ Object

About to attempt to register as node_name



56
57
# File 'lib/minimal-diff-chef-formatter.rb', line 56

def registration_start(node_name, config)
end

#removed_cookbook_file(path) ⇒ Object

Called after the file at path is removed. It may be removed if the cookbook containing it was removed from the run list, or if the file was removed from the cookbook.



102
103
# File 'lib/minimal-diff-chef-formatter.rb', line 102

def removed_cookbook_file(path)
end

#resource_action_start(resource, action, notification_type = nil, notifier = nil) ⇒ Object

Called before action is executed on a resource.



171
172
# File 'lib/minimal-diff-chef-formatter.rb', line 171

def resource_action_start(resource, action, notification_type=nil, notifier=nil)
end

#resource_current_state_loaded(resource, action, current_resource) ⇒ Object

Called after #load_current_resource has run.



188
189
# File 'lib/minimal-diff-chef-formatter.rb', line 188

def resource_current_state_loaded(resource, action, current_resource)
end

#resource_failed(resource, action, exception) ⇒ Object

Called when a resource fails and will not be retried.



179
180
# File 'lib/minimal-diff-chef-formatter.rb', line 179

def resource_failed(resource, action, exception)
end

#resource_failed_retriable(resource, action, retry_count, exception) ⇒ Object

Called when a resource fails, but will retry.



175
176
# File 'lib/minimal-diff-chef-formatter.rb', line 175

def resource_failed_retriable(resource, action, retry_count, exception)
end

#resource_skipped(resource, action, conditional) ⇒ Object

Called when a resource action has been skipped b/c of a conditional



183
184
185
# File 'lib/minimal-diff-chef-formatter.rb', line 183

def resource_skipped(resource, action, conditional)
  print "S"
end

#resource_up_to_date(resource, action) ⇒ Object

Called when a resource has no converge actions, e.g., it was already correct.



192
193
194
# File 'lib/minimal-diff-chef-formatter.rb', line 192

def resource_up_to_date(resource, action)
  print "."
end

#resource_update_applied(resource, action, update) ⇒ Object

Called when a change has been made to a resource. May be called multiple times per resource, e.g., a file may have its content updated, and then its permissions updated.



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/minimal-diff-chef-formatter.rb', line 203

def resource_update_applied(resource, action, update)
  prefix = Chef::Config[:why_run] ? "Would " : ""
  Array(update).each do |line|
    next if line.nil?
    if line.kind_of? String
      @updates_by_resource[resource.name] << "    - #{prefix}#{line}"
    elsif line.kind_of? Array
      # Expanded output - delta
      # @todo should we have a resource_update_delta callback?
      line.each do |detail|
        @updates_by_resource[resource.name] << "        #{detail}"
      end
    end
  end
end

#resource_updated(resource, action) ⇒ Object

Called after a resource has been completely converged.



220
221
222
223
# File 'lib/minimal-diff-chef-formatter.rb', line 220

def resource_updated(resource, action)
  updated_resources << resource
  print "U"
end

#run_completed(node) ⇒ Object

Called at the end of the Chef run.



38
39
40
# File 'lib/minimal-diff-chef-formatter.rb', line 38

def run_completed(node)
  puts "chef client finished, #{@updated_resources.size} resources updated"
end

#run_failed(exception) ⇒ Object

called at the end of a failed run



43
44
45
# File 'lib/minimal-diff-chef-formatter.rb', line 43

def run_failed(exception)
  puts "chef client failed. #{@updated_resources.size} resources updated"
end

#run_start(version) ⇒ Object

Called at the very start of a Chef Run



33
34
35
# File 'lib/minimal-diff-chef-formatter.rb', line 33

def run_start(version)
  puts "Starting Chef Client, version #{version}"
end

#skipping_registration(node_name, config) ⇒ Object

Already have a client key, assuming this node has registered.



52
53
# File 'lib/minimal-diff-chef-formatter.rb', line 52

def skipping_registration(node_name, config)
end

#synchronized_cookbook(cookbook_name) ⇒ Object

Called when cookbook cookbook_name has been sync’d



115
116
117
# File 'lib/minimal-diff-chef-formatter.rb', line 115

def synchronized_cookbook(cookbook_name)
  print "."
end

#updated_cookbook_file(cookbook_name, path) ⇒ Object

Called when an individual file in a cookbook has been updated



120
121
# File 'lib/minimal-diff-chef-formatter.rb', line 120

def updated_cookbook_file(cookbook_name, path)
end