nice-chef-formatter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +42 -0
- data/lib/chef/formatters/coloredputter.rb +76 -0
- data/lib/nice-chef-formatter.rb +110 -0
- data/nice-chef-formatter.gemspec +19 -0
- metadata +66 -0
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Nice Chef Formatter
|
2
|
+
===================
|
3
|
+
|
4
|
+
Formatter for chef with execution times for every cookbook/recipe and simplified output.
|
5
|
+
|
6
|
+
Color codes:
|
7
|
+
- Green, resource had nothing to do. It was already applied
|
8
|
+
- Yellow, resource has done work. Applied
|
9
|
+
- Blue, resource was skipped due to conditional (only_if, not_if, ...)
|
10
|
+
|
11
|
+
Usage
|
12
|
+
=====
|
13
|
+
|
14
|
+
Install the gem:
|
15
|
+
|
16
|
+
gem install nice-chef-formatter
|
17
|
+
|
18
|
+
If you are using Omnibus Chef you need to specify the full path to the `gem`
|
19
|
+
binary:
|
20
|
+
|
21
|
+
/opt/chef/embedded/bin/gem install nice-chef-formatter
|
22
|
+
|
23
|
+
Or write a cookbook to install it using the `chef_gem` resource, if that's
|
24
|
+
how you roll.
|
25
|
+
|
26
|
+
Then add the following to your `/etc/chef/client.rb` file:
|
27
|
+
|
28
|
+
gem 'nice-chef-formatter'
|
29
|
+
require 'nice-chef-formatter'
|
30
|
+
|
31
|
+
This enables the formatter, but doesn't use it by default.
|
32
|
+
|
33
|
+
Acknowledgements
|
34
|
+
================
|
35
|
+
|
36
|
+
* Andrea Campi (@andreacampi) for the [nyan-cat-chef-formatter](https://github.com/andreacampi/nyan-cat-chef-formatter) that was the original inspiration
|
37
|
+
|
38
|
+
License and Authors
|
39
|
+
===================
|
40
|
+
|
41
|
+
Author:: Nadir Lloret (<nadir.lloret@gmail.com>)
|
42
|
+
License:: Apache 2.0
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'chef/formatters/base'
|
2
|
+
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
module Formatters
|
6
|
+
class Coloredputter < Outputter
|
7
|
+
def initialize(out, err)
|
8
|
+
super(out, err)
|
9
|
+
if OS.windows?
|
10
|
+
require 'Win32API'
|
11
|
+
get_std_handle = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L')
|
12
|
+
@stdout = get_std_handle.call(-11)
|
13
|
+
@set_console_txt_attrb = Win32API.new("kernel32", "SetConsoleTextAttribute", ['L','N'], 'I')
|
14
|
+
elsif OS.linux?
|
15
|
+
require 'rainbow'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def puts(string, *color)
|
20
|
+
if OS.linux?
|
21
|
+
case color[0]
|
22
|
+
when 'green'
|
23
|
+
@out.puts Rainbow(string).color(:green)
|
24
|
+
when 'yellow'
|
25
|
+
@out.puts Rainbow(string).color(:yellow)
|
26
|
+
when 'red'
|
27
|
+
@out.puts Rainbow(string).color(:red)
|
28
|
+
when 'blue'
|
29
|
+
@out.puts Rainbow(string).color(:blue)
|
30
|
+
else
|
31
|
+
@out.puts string
|
32
|
+
end
|
33
|
+
elsif OS.windows?
|
34
|
+
case color[0]
|
35
|
+
when 'green'
|
36
|
+
@set_console_txt_attrb.call(@stdout, 90)
|
37
|
+
@out.puts string
|
38
|
+
when 'yellow'
|
39
|
+
@set_console_txt_attrb.call(@stdout, 94)
|
40
|
+
@out.puts string
|
41
|
+
when 'red'
|
42
|
+
@set_console_txt_attrb.call(@stdout, 92)
|
43
|
+
@out.puts string
|
44
|
+
when 'blue'
|
45
|
+
@set_console_txt_attrb.call(@stdout, 91)
|
46
|
+
@out.puts string
|
47
|
+
else
|
48
|
+
@set_console_txt_attrb.call(@stdout, 95)
|
49
|
+
@out.puts string
|
50
|
+
end
|
51
|
+
@set_console_txt_attrb.call(@stdout, 95)
|
52
|
+
else
|
53
|
+
@out.puts string
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module OS
|
60
|
+
def OS.windows?
|
61
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def OS.mac?
|
65
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def OS.unix?
|
69
|
+
!OS.windows?
|
70
|
+
end
|
71
|
+
|
72
|
+
def OS.linux?
|
73
|
+
OS.unix? and not OS.mac?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'chef/formatters/minimal'
|
2
|
+
require 'chef/formatters/coloredputter'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
module Formatters
|
6
|
+
class Nice < Formatters::Base
|
7
|
+
|
8
|
+
cli_name(:nice)
|
9
|
+
|
10
|
+
# Override parent class
|
11
|
+
def initialize(out, err)
|
12
|
+
super
|
13
|
+
@output = Coloredputter.new(out, err)
|
14
|
+
livedrive_title = "
|
15
|
+
=====================================================================
|
16
|
+
=====================================================================
|
17
|
+
|
18
|
+
dP\"\"b8 88 88 888888 888888 88\"\"Yb 88 88 88b 88
|
19
|
+
dP `I 88 88 88__ 88__ 88__dP 88 88 88Yb88
|
20
|
+
Yb 888888 88\"\" 88\"\" 88\"Yb Y8 8P 88 Y88
|
21
|
+
YboodP 88 88 888888 88 88 Yb `YbodP' 88 Y8
|
22
|
+
|
23
|
+
=====================================================================
|
24
|
+
=====================================================================
|
25
|
+
"
|
26
|
+
puts livedrive_title
|
27
|
+
end
|
28
|
+
|
29
|
+
# Called at the very start of a Chef Run
|
30
|
+
def run_start(version)
|
31
|
+
puts "Starting Chef Client, version #{version}"
|
32
|
+
@initial_time = Time.now.to_f
|
33
|
+
end
|
34
|
+
|
35
|
+
# Called before the cookbook collection is fetched from the server.
|
36
|
+
def cookbook_resolution_start(expanded_run_list)
|
37
|
+
puts "Very run list: #{expanded_run_list.inspect}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def cookbook_sync_start(cookbook_count)
|
41
|
+
puts "Cookbook synchronization"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Called when cookbook +cookbook_name+ has been sync'd
|
45
|
+
def synchronized_cookbook(cookbook_name)
|
46
|
+
puts " - #{cookbook_name}"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Called after all cookbooks have been sync'd.
|
50
|
+
def cookbook_sync_complete
|
51
|
+
puts "Finish cookbook synchronization"
|
52
|
+
end
|
53
|
+
|
54
|
+
def converge_start(run_context)
|
55
|
+
puts "Converge #{run_context.resource_collection.all_resources.size} resources"
|
56
|
+
end
|
57
|
+
|
58
|
+
def converge_complete
|
59
|
+
total_exec_time = Time.now.to_f - @initial_time
|
60
|
+
puts "System converged in #{total_exec_time.round(2)}"
|
61
|
+
end
|
62
|
+
|
63
|
+
# Called when cookbook loading starts.
|
64
|
+
def library_load_start(file_count)
|
65
|
+
puts "Compilation"
|
66
|
+
end
|
67
|
+
|
68
|
+
def resource_action_start(resource, action, notification_type=nil, notifier=nil)
|
69
|
+
if resource.cookbook_name && resource.recipe_name
|
70
|
+
resource_recipe = "#{resource.cookbook_name}::#{resource.recipe_name}"
|
71
|
+
else
|
72
|
+
puts "#{resource.cookbook_name}::#{resource.recipe_name}"
|
73
|
+
resource_recipe = "<wow, so much LWRP>"
|
74
|
+
end
|
75
|
+
|
76
|
+
if resource_recipe != @current_recipe
|
77
|
+
if @recipe_start_time
|
78
|
+
recipe_exec_time = Time.now.to_f - @recipe_start_time
|
79
|
+
puts "(#{recipe_exec_time.round(3)} secs)"
|
80
|
+
end
|
81
|
+
puts "Recipe: #{resource_recipe}"
|
82
|
+
@current_recipe = resource_recipe
|
83
|
+
@recipe_start_time = Time.now.to_f
|
84
|
+
end
|
85
|
+
@resource_start_time = Time.now.to_f
|
86
|
+
end
|
87
|
+
|
88
|
+
# Called when a resource action has been skipped b/c of a conditional
|
89
|
+
def resource_skipped(resource, action, conditional)
|
90
|
+
# Output should be blue (Skipped)
|
91
|
+
resource_exec_time = Time.now.to_f - @resource_start_time
|
92
|
+
puts(" * #{resource} action #{action} (#{resource_exec_time.round(3)} secs)", 'blue')
|
93
|
+
end
|
94
|
+
|
95
|
+
# Called when a resource has no converge actions, e.g., it was already correct.
|
96
|
+
def resource_up_to_date(resource, action)
|
97
|
+
# Output should be green
|
98
|
+
resource_exec_time = Time.now.to_f - @resource_start_time
|
99
|
+
puts(" * #{resource} action #{action} (#{resource_exec_time.round(3)} secs)", 'green')
|
100
|
+
end
|
101
|
+
|
102
|
+
# Called after a resource has been completely converged.
|
103
|
+
def resource_updated(resource, action)
|
104
|
+
# Output should be yellow (changes are applied)
|
105
|
+
resource_exec_time = Time.now.to_f - @resource_start_time
|
106
|
+
puts(" * #{resource} action #{action} (#{resource_exec_time.round(3)} secs)", 'yellow')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "nice-chef-formatter"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.authors = ["Nadir Lloret"]
|
7
|
+
s.email = ["nadir.lloret@livedrive.com"]
|
8
|
+
s.homepage = "https://github.com/nadirollo/nice-chef-formatter"
|
9
|
+
s.summary = %q{Nice Chef log formatter}
|
10
|
+
s.description = %q{Simple formatted output for chef with execution times and color for resource action results}
|
11
|
+
|
12
|
+
s.rubyforge_project = "nice-chef-formatter"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.add_runtime_dependency "rainbow"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nice-chef-formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nadir Lloret
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rainbow
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Simple formatted output for chef with execution times and color for resource
|
31
|
+
action results
|
32
|
+
email:
|
33
|
+
- nadir.lloret@livedrive.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- README.md
|
39
|
+
- lib/chef/formatters/coloredputter.rb
|
40
|
+
- lib/nice-chef-formatter.rb
|
41
|
+
- nice-chef-formatter.gemspec
|
42
|
+
homepage: https://github.com/nadirollo/nice-chef-formatter
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: nice-chef-formatter
|
62
|
+
rubygems_version: 1.8.23
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Nice Chef log formatter
|
66
|
+
test_files: []
|