Class: Chef::Formatters::Voxer
- Inherits:
-
Formatters::Base
- Object
- Formatters::Base
- Chef::Formatters::Voxer
- Defined in:
- lib/voxer-chef-formatter.rb
Constant Summary collapse
- COLOR_RED =
"\e[31m"- COLOR_GREEN =
"\e[32m"- COLOR_MAGENTA =
"\e[35m"- COLOR_RESET =
"\e[0m"
Instance Method Summary collapse
-
#colorize_diff(diff) ⇒ Object
helper functions.
-
#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.
-
#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.
-
#initialize(out, err) ⇒ Voxer
constructor
A new instance of Voxer.
-
#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.
-
#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. -
#updated_cookbook_file(cookbook_name, path) ⇒ Object
Called when an individual file in a cookbook has been updated.
Constructor Details
#initialize(out, err) ⇒ Voxer
Returns a new instance of Voxer.
31 32 33 34 35 36 |
# File 'lib/voxer-chef-formatter.rb', line 31 def initialize(out, err) super @start_time = Time.now @updated_resources = 0 @updates_by_resource = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#colorize_diff(diff) ⇒ Object
helper functions
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/voxer-chef-formatter.rb', line 261 def colorize_diff(diff) diff.map do |l| f = ' ' if l.start_with?('-') then f += COLOR_RED elsif l.start_with?('+') then f += COLOR_GREEN elsif l.start_with?('@') then f += COLOR_MAGENTA end f += l f += COLOR_RESET f end end |
#converge_complete ⇒ Object
Called when the converge phase is finished.
178 179 |
# File 'lib/voxer-chef-formatter.rb', line 178 def converge_complete end |
#converge_start(run_context) ⇒ Object
Called before convergence starts
173 174 175 |
# File 'lib/voxer-chef-formatter.rb', line 173 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.
127 128 |
# File 'lib/voxer-chef-formatter.rb', line 127 def cookbook_clean_complete end |
#cookbook_clean_start ⇒ Object
Called before unneeded cookbooks are removed
117 118 |
# File 'lib/voxer-chef-formatter.rb', line 117 def cookbook_clean_start end |
#cookbook_resolution_complete(cookbook_collection) ⇒ Object
Called when the cookbook collection is returned from the server.
113 114 |
# File 'lib/voxer-chef-formatter.rb', line 113 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.
109 110 |
# File 'lib/voxer-chef-formatter.rb', line 109 def cookbook_resolution_failed(, exception) end |
#cookbook_resolution_start(expanded_run_list) ⇒ Object
Called before the cookbook collection is fetched from the server.
103 104 105 |
# File 'lib/voxer-chef-formatter.rb', line 103 def cookbook_resolution_start() puts "resolving cookbooks for run list: #{expanded_run_list.inspect}" end |
#cookbook_sync_complete ⇒ Object
Called after all cookbooks have been sync’d.
145 146 147 |
# File 'lib/voxer-chef-formatter.rb', line 145 def cookbook_sync_complete puts 'done.' end |
#cookbook_sync_start(cookbook_count) ⇒ Object
Called before cookbook sync starts
131 132 133 |
# File 'lib/voxer-chef-formatter.rb', line 131 def cookbook_sync_start(cookbook_count) puts 'synchronizing cookbooks' end |
#file_load_failed(path, exception) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/voxer-chef-formatter.rb', line 159 def file_load_failed(path, exception) puts COLOR_RED puts "failed to load file --> #{path}" puts " --> #{exception}" puts COLOR_RESET super end |
#file_loaded(path) ⇒ Object
Called after a file in a cookbook is loaded.
155 156 157 |
# File 'lib/voxer-chef-formatter.rb', line 155 def file_loaded(path) print '.' end |
#handler_executed(handler) ⇒ Object
Called after an individual handler has run
245 246 |
# File 'lib/voxer-chef-formatter.rb', line 245 def handler_executed(handler) end |
#handlers_completed ⇒ Object
Called after all handlers have executed
249 250 |
# File 'lib/voxer-chef-formatter.rb', line 249 def handlers_completed end |
#handlers_start(handler_count) ⇒ Object
Called before handlers run
241 242 |
# File 'lib/voxer-chef-formatter.rb', line 241 def handlers_start(handler_count) end |
#library_load_start(file_count) ⇒ Object
Called when cookbook loading starts.
150 151 152 |
# File 'lib/voxer-chef-formatter.rb', line 150 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.
257 258 |
# File 'lib/voxer-chef-formatter.rb', line 257 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.
99 100 |
# File 'lib/voxer-chef-formatter.rb', line 99 def node_load_completed(node, , config) end |
#node_load_failed(node_name, exception, config) ⇒ Object
Failed to load node data from the server
94 95 |
# File 'lib/voxer-chef-formatter.rb', line 94 def node_load_failed(node_name, exception, config) end |
#node_load_start(node_name, config) ⇒ Object
90 91 |
# File 'lib/voxer-chef-formatter.rb', line 90 def node_load_start(node_name, config) end |
#ohai_completed(node) ⇒ Object
Called right after ohai runs.
71 72 |
# File 'lib/voxer-chef-formatter.rb', line 71 def ohai_completed(node) end |
#recipe_load_complete ⇒ Object
Called when recipes have been loaded.
168 169 170 |
# File 'lib/voxer-chef-formatter.rb', line 168 def recipe_load_complete puts 'done.' end |
#registration_completed ⇒ Object
82 83 |
# File 'lib/voxer-chef-formatter.rb', line 82 def registration_completed end |
#registration_failed(node_name, exception, config) ⇒ Object
Failed to register this client with the server.
86 87 88 |
# File 'lib/voxer-chef-formatter.rb', line 86 def registration_failed(node_name, exception, config) super end |
#registration_start(node_name, config) ⇒ Object
About to attempt to register as node_name
79 80 |
# File 'lib/voxer-chef-formatter.rb', line 79 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.
123 124 |
# File 'lib/voxer-chef-formatter.rb', line 123 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.
182 183 |
# File 'lib/voxer-chef-formatter.rb', line 182 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.
202 203 |
# File 'lib/voxer-chef-formatter.rb', line 202 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.
190 191 192 193 194 195 |
# File 'lib/voxer-chef-formatter.rb', line 190 def resource_failed(resource, action, exception) puts COLOR_RED puts "failed to handle resource --> :#{action} #{resource}" puts COLOR_RESET puts "#{exception}" end |
#resource_failed_retriable(resource, action, retry_count, exception) ⇒ Object
Called when a resource fails, but will retry.
186 187 |
# File 'lib/voxer-chef-formatter.rb', line 186 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
198 199 |
# File 'lib/voxer-chef-formatter.rb', line 198 def resource_skipped(resource, action, conditional) end |
#resource_up_to_date(resource, action) ⇒ Object
Called when a resource has no converge actions, e.g., it was already correct.
206 207 |
# File 'lib/voxer-chef-formatter.rb', line 206 def resource_up_to_date(resource, action) 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.
216 217 218 |
# File 'lib/voxer-chef-formatter.rb', line 216 def resource_update_applied(resource, action, update) @updates_by_resource[resource.name] << update end |
#resource_updated(resource, action) ⇒ Object
Called after a resource has been completely converged.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/voxer-chef-formatter.rb', line 221 def resource_updated(resource, action) @updated_resources += 1 puts "* #{resource.to_s}" @updates_by_resource[resource.name].each do |update| u = Array(update) # print what happened in green puts "#{COLOR_GREEN} - #{u[0]}#{COLOR_RESET}" if u[1].is_a?(Array) then # most likely a diff puts '' puts colorize_diff(u[1]).join("\n") end end puts '' end |
#run_completed(node) ⇒ Object
Called at the end of the Chef run.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/voxer-chef-formatter.rb', line 44 def run_completed(node) chef_dir = Chef::Config[:root_path] now = Time.now elapsed = (now - @start_time).round(2) file = ENV['VOXER_FORMATTER_FILE'] unless file.nil? data = { :finished => now, :elapsed => elapsed, :dir => chef_dir, :git => { :branch => `git --git-dir #{chef_dir}/.git rev-parse --abbrev-ref HEAD 2>&1`.strip, :commit => `git --git-dir #{chef_dir}/.git rev-parse HEAD 2>&1`.strip } } IO.write(file, JSON.pretty_generate(data) + "\n") end puts "chef client finished. #{@updated_resources} resources updated, took #{elapsed} seconds" end |
#run_failed(exception) ⇒ Object
called at the end of a failed run
65 66 67 68 |
# File 'lib/voxer-chef-formatter.rb', line 65 def run_failed(exception) elapsed = (Time.now - @start_time).round(2) puts "chef client failed. #{@updated_resources} resources updated, took #{elapsed} seconds" end |
#run_start(version) ⇒ Object
Called at the very start of a Chef Run
39 40 41 |
# File 'lib/voxer-chef-formatter.rb', line 39 def run_start(version) puts "starting chef, version #{version}" end |
#skipping_registration(node_name, config) ⇒ Object
Already have a client key, assuming this node has registered.
75 76 |
# File 'lib/voxer-chef-formatter.rb', line 75 def skipping_registration(node_name, config) end |
#synchronized_cookbook(cookbook_name) ⇒ Object
Called when cookbook cookbook_name has been sync’d
136 137 138 |
# File 'lib/voxer-chef-formatter.rb', line 136 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
141 142 |
# File 'lib/voxer-chef-formatter.rb', line 141 def updated_cookbook_file(cookbook_name, path) end |