Class: Chef::Formatters::Simple
- Inherits:
-
Formatters::Base
- Object
- Formatters::Base
- Chef::Formatters::Simple
- Defined in:
- lib/chef/formatters/simple.rb
Overview
Formatters::Simple
Shows the progress of the chef run by printing single characters, and displays a summary of updates at the conclusion of the run. For events that don’t have meaningful status information (loading a file, syncing a cookbook) a dot is printed. For resources, a dot, ‘S’ or ‘U’ is printed if the resource is up to date, skipped by not_if/only_if, or updated, respectively.
Instance Attribute Summary collapse
-
#updated_resources ⇒ Object
readonly
Returns the value of attribute updated_resources.
-
#updates_by_resource ⇒ Object
readonly
Returns the value of attribute updates_by_resource.
Instance Method Summary collapse
-
#converge_complete ⇒ Object
Called when the converge phase is finished.
-
#converge_start(run_context) ⇒ Object
Called before convergence starts.
-
#cookbook_clean_complete ⇒ Object
Called when cookbook cleaning is finished.
-
#cookbook_clean_start ⇒ Object
Called before unneeded cookbooks are removed – TODO: Should be called in CookbookVersion.sync_cookbooks.
-
#cookbook_resolution_complete(cookbook_collection) ⇒ Object
Called when the cookbook collection is returned from the server.
-
#cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object
Called when there is an error getting the cookbook collection from the server.
-
#cookbook_resolution_start(expanded_run_list) ⇒ Object
Called before the cookbook collection is fetched from the server.
-
#cookbook_sync_complete ⇒ Object
Called after all cookbooks have been sync’d.
-
#cookbook_sync_start(cookbook_count) ⇒ Object
Called before cookbook sync starts.
- #file_load_failed(path, exception) ⇒ Object
-
#file_loaded(path) ⇒ Object
Called after a file in a cookbook is loaded.
-
#handler_executed(handler) ⇒ Object
Called after an individual handler has run.
-
#handlers_completed ⇒ Object
Called after all handlers have executed.
-
#handlers_start(handler_count) ⇒ Object
Called before handlers run.
- #indent ⇒ Object
-
#initialize(out, err) ⇒ Simple
constructor
A new instance of Simple.
-
#library_load_start(file_count) ⇒ Object
Called when cookbook loading starts.
-
#msg(message) ⇒ Object
An uncategorized message.
-
#node_load_completed(node, expanded_run_list, config) ⇒ Object
Default and override attrs from roles have been computed, but not yet applied.
-
#node_load_failed(node_name, exception, config) ⇒ Object
Failed to load node data from the server.
- #node_load_start(node_name, config) ⇒ Object
-
#ohai_completed(node) ⇒ Object
Called right after ohai runs.
- #output_record(line) ⇒ Object
-
#recipe_load_complete ⇒ Object
Called when recipes have been loaded.
- #registration_completed ⇒ Object
-
#registration_failed(node_name, exception, config) ⇒ Object
Failed to register this client with the server.
-
#registration_start(node_name, config) ⇒ Object
About to attempt to register as
node_name. -
#removed_cookbook_file(path) ⇒ Object
Called after the file at
pathis removed. -
#resource_action_start(resource, action, notification_type = nil, notifier = nil) ⇒ Object
Called before action is executed on a resource.
-
#resource_current_state_loaded(resource, action, current_resource) ⇒ Object
Called after #load_current_resource has run.
-
#resource_failed(resource, action, exception) ⇒ Object
Called when a resource fails and will not be retried.
-
#resource_failed_retriable(resource, action, retry_count, exception) ⇒ Object
Called when a resource fails, but will retry.
-
#resource_skipped(resource, action, conditional) ⇒ Object
Called when a resource action has been skipped b/c of a conditional.
-
#resource_up_to_date(resource, action) ⇒ Object
Called when a resource has no converge actions, e.g., it was already correct.
-
#resource_update_applied(resource, action, update) ⇒ Object
Called when a change has been made to a resource.
-
#resource_updated(resource, action) ⇒ Object
Called after a resource has been completely converged.
-
#run_completed(node) ⇒ Object
Called at the end of the Chef run.
-
#run_failed(exception) ⇒ Object
called at the end of a failed run.
-
#run_start(version) ⇒ Object
Called at the very start of a Chef Run.
-
#skipping_registration(node_name, config) ⇒ Object
Already have a client key, assuming this node has registered.
-
#synchronized_cookbook(cookbook_name) ⇒ Object
Called when cookbook
cookbook_namehas been sync’d. - #unindent ⇒ Object
-
#updated_cookbook_file(cookbook_name, path) ⇒ Object
Called when an individual file in a cookbook has been updated.
Constructor Details
#initialize(out, err) ⇒ Simple
Returns a new instance of Simple.
24 25 26 27 28 |
# File 'lib/chef/formatters/simple.rb', line 24 def initialize(out, err) super @updated_resources = [] @updates_by_resource = Hash.new {|h, k| h[k] = []} end |
Instance Attribute Details
#updated_resources ⇒ Object (readonly)
Returns the value of attribute updated_resources.
20 21 22 |
# File 'lib/chef/formatters/simple.rb', line 20 def updated_resources @updated_resources end |
#updates_by_resource ⇒ Object (readonly)
Returns the value of attribute updates_by_resource.
21 22 23 |
# File 'lib/chef/formatters/simple.rb', line 21 def updates_by_resource @updates_by_resource end |
Instance Method Details
#converge_complete ⇒ Object
Called when the converge phase is finished.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/chef/formatters/simple.rb', line 153 def converge_complete prefix = Chef::Config[:why_run] ? "Would " : "" 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| if resource.cookbook_name && resource.recipe_name resource_recipe = "#{resource.cookbook_name}::#{resource.recipe_name}" else resource_recipe = "<Dynamically Defined Resource>" end if resource_recipe != @current_recipe && !resource.enclosing_provider unindent if @current_recipe puts_line "Recipe: #{resource_recipe}" @current_recipe = resource_recipe indent end puts "* #{resource.to_s}" updates_by_resource[resource.name].each do |update| Array(update).each do |line| next if line.nil? output_record line if line.kind_of? String start_line "- #{prefix}#{line}", :green elsif line.kind_of? Array # Expanded output - delta # @todo should we have a resource_update_delta callback? indent line.each do |detail| start_line detail, :white end unindent end end end puts "\n" end end end |
#converge_start(run_context) ⇒ Object
Called before convergence starts
148 149 150 |
# File 'lib/chef/formatters/simple.rb', line 148 def converge_start(run_context) puts "Converging #{run_context.resource_collection.all_resources.size} resources" end |
#cookbook_clean_complete ⇒ Object
Called when cookbook cleaning is finished.
106 107 |
# File 'lib/chef/formatters/simple.rb', line 106 def cookbook_clean_complete end |
#cookbook_clean_start ⇒ Object
Called before unneeded cookbooks are removed – TODO: Should be called in CookbookVersion.sync_cookbooks
96 97 |
# File 'lib/chef/formatters/simple.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/chef/formatters/simple.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.
85 86 87 |
# File 'lib/chef/formatters/simple.rb', line 85 def cookbook_resolution_failed(, exception) super end |
#cookbook_resolution_start(expanded_run_list) ⇒ Object
Called before the cookbook collection is fetched from the server.
79 80 81 |
# File 'lib/chef/formatters/simple.rb', line 79 def cookbook_resolution_start() puts "resolving cookbooks for run list: #{.inspect}" end |
#cookbook_sync_complete ⇒ Object
Called after all cookbooks have been sync’d.
124 125 126 |
# File 'lib/chef/formatters/simple.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/chef/formatters/simple.rb', line 110 def cookbook_sync_start(cookbook_count) puts "Synchronizing cookbooks" end |
#file_load_failed(path, exception) ⇒ Object
138 139 140 |
# File 'lib/chef/formatters/simple.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/chef/formatters/simple.rb', line 134 def file_loaded(path) print '.' end |
#handler_executed(handler) ⇒ Object
Called after an individual handler has run
250 251 |
# File 'lib/chef/formatters/simple.rb', line 250 def handler_executed(handler) end |
#handlers_completed ⇒ Object
Called after all handlers have executed
254 255 |
# File 'lib/chef/formatters/simple.rb', line 254 def handlers_completed end |
#handlers_start(handler_count) ⇒ Object
Called before handlers run
246 247 |
# File 'lib/chef/formatters/simple.rb', line 246 def handlers_start(handler_count) end |
#indent ⇒ Object
265 266 267 |
# File 'lib/chef/formatters/simple.rb', line 265 def indent indent_by(2) end |
#library_load_start(file_count) ⇒ Object
Called when cookbook loading starts.
129 130 131 |
# File 'lib/chef/formatters/simple.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.
262 263 |
# File 'lib/chef/formatters/simple.rb', line 262 def msg() 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.
75 76 |
# File 'lib/chef/formatters/simple.rb', line 75 def node_load_completed(node, , config) end |
#node_load_failed(node_name, exception, config) ⇒ Object
Failed to load node data from the server
69 70 71 |
# File 'lib/chef/formatters/simple.rb', line 69 def node_load_failed(node_name, exception, config) super end |
#node_load_start(node_name, config) ⇒ Object
65 66 |
# File 'lib/chef/formatters/simple.rb', line 65 def node_load_start(node_name, config) end |
#ohai_completed(node) ⇒ Object
Called right after ohai runs.
46 47 |
# File 'lib/chef/formatters/simple.rb', line 46 def ohai_completed(node) end |
#output_record(line) ⇒ Object
197 198 |
# File 'lib/chef/formatters/simple.rb', line 197 def output_record(line) end |
#recipe_load_complete ⇒ Object
Called when recipes have been loaded.
143 144 145 |
# File 'lib/chef/formatters/simple.rb', line 143 def recipe_load_complete puts "done." end |
#registration_completed ⇒ Object
57 58 |
# File 'lib/chef/formatters/simple.rb', line 57 def registration_completed end |
#registration_failed(node_name, exception, config) ⇒ Object
Failed to register this client with the server.
61 62 63 |
# File 'lib/chef/formatters/simple.rb', line 61 def registration_failed(node_name, exception, config) super end |
#registration_start(node_name, config) ⇒ Object
About to attempt to register as node_name
54 55 |
# File 'lib/chef/formatters/simple.rb', line 54 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/chef/formatters/simple.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.
201 202 |
# File 'lib/chef/formatters/simple.rb', line 201 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.
220 221 |
# File 'lib/chef/formatters/simple.rb', line 220 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.
210 211 212 |
# File 'lib/chef/formatters/simple.rb', line 210 def resource_failed(resource, action, exception) super end |
#resource_failed_retriable(resource, action, retry_count, exception) ⇒ Object
Called when a resource fails, but will retry.
205 206 207 |
# File 'lib/chef/formatters/simple.rb', line 205 def resource_failed_retriable(resource, action, retry_count, exception) super end |
#resource_skipped(resource, action, conditional) ⇒ Object
Called when a resource action has been skipped b/c of a conditional
215 216 217 |
# File 'lib/chef/formatters/simple.rb', line 215 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.
224 225 226 |
# File 'lib/chef/formatters/simple.rb', line 224 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.
235 236 237 |
# File 'lib/chef/formatters/simple.rb', line 235 def resource_update_applied(resource, action, update) @updates_by_resource[resource.name] << Array(update) #[0] end |
#resource_updated(resource, action) ⇒ Object
Called after a resource has been completely converged.
240 241 242 243 |
# File 'lib/chef/formatters/simple.rb', line 240 def resource_updated(resource, action) updated_resources << resource print "U" end |
#run_completed(node) ⇒ Object
Called at the end of the Chef run.
36 37 38 |
# File 'lib/chef/formatters/simple.rb', line 36 def run_completed(node) @output.puts "chef client finished, #{@updated_resources.size} resources updated", :green end |
#run_failed(exception) ⇒ Object
called at the end of a failed run
41 42 43 |
# File 'lib/chef/formatters/simple.rb', line 41 def run_failed(exception) @output.puts "\nchef client failed. #{@updated_resources.size} resources updated", :red end |
#run_start(version) ⇒ Object
Called at the very start of a Chef Run
31 32 33 |
# File 'lib/chef/formatters/simple.rb', line 31 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.
50 51 |
# File 'lib/chef/formatters/simple.rb', line 50 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/chef/formatters/simple.rb', line 115 def synchronized_cookbook(cookbook_name) print "." end |
#unindent ⇒ Object
269 270 271 |
# File 'lib/chef/formatters/simple.rb', line 269 def unindent indent_by(-2) end |
#updated_cookbook_file(cookbook_name, path) ⇒ Object
Called when an individual file in a cookbook has been updated
120 121 |
# File 'lib/chef/formatters/simple.rb', line 120 def updated_cookbook_file(cookbook_name, path) end |