chef-undev 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/chef-undev.gemspec +25 -0
- data/lib/chef/undev/formatters/silent.rb +135 -0
- data/lib/chef/undev/handler/reporter.rb +40 -0
- data/lib/chef/undev/monkey_patches/load_prior_resource.rb +19 -0
- data/lib/chef/undev/monkey_patches/verbose.rb +1 -0
- data/lib/chef/undev/support/color_diff.rb +38 -0
- data/lib/chef/undev/version.rb +5 -0
- data/lib/chef/undev.rb +0 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Vasiliev Dmitry
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Chef::Undev
|
2
|
+
|
3
|
+
## Делаем chef тихим
|
4
|
+
|
5
|
+
В client.rb включаем:
|
6
|
+
|
7
|
+
require 'chef/undev/formatters/silent'
|
8
|
+
|
9
|
+
И запускаем клиент:
|
10
|
+
|
11
|
+
chef-client -F undev
|
12
|
+
|
13
|
+
## Хандлеры для chef-run
|
14
|
+
|
15
|
+
В client.rb:
|
16
|
+
|
17
|
+
require 'chef/undev/handler/reporter'
|
18
|
+
|
19
|
+
handler = Undev::Handler.new
|
20
|
+
report_handlers << handler
|
21
|
+
exception_handlers << handler
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/chef-undev.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chef/undev/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'chef-undev'
|
8
|
+
spec.version = Chef::Undev::VERSION
|
9
|
+
spec.authors = ['Vasiliev Dmitry']
|
10
|
+
spec.email = %w(vadv.mkn@gmail.com)
|
11
|
+
spec.description = %q{Chef client patches for undev}
|
12
|
+
spec.summary = %q{Silent formatters, handler report}
|
13
|
+
spec.homepage = 'http://git.undev.cc/megaadmins/chef-undev'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = %w(lib)
|
20
|
+
|
21
|
+
spec.add_dependency('chef')
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'chef/formatters/minimal'
|
2
|
+
|
3
|
+
require_relative '../support/color_diff'
|
4
|
+
require_relative '../monkey_patches/load_prior_resource'
|
5
|
+
require_relative '../monkey_patches/verbose'
|
6
|
+
|
7
|
+
class Chef
|
8
|
+
module Formatters
|
9
|
+
class Silent < Formatters::Minimal
|
10
|
+
|
11
|
+
cli_name(:undev)
|
12
|
+
cli_name(:silent)
|
13
|
+
|
14
|
+
def run_start(version)
|
15
|
+
puts "Starting Chef Client, version #{version}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_completed(node)
|
19
|
+
puts "Chef client finished, #{@updated_resources.size} resources updated"
|
20
|
+
end
|
21
|
+
|
22
|
+
def run_failed(exception)
|
23
|
+
puts "Chef client failed. #{@updated_resources.size} resources updated"
|
24
|
+
end
|
25
|
+
|
26
|
+
def cookbook_resolution_start(expanded_run_list)
|
27
|
+
puts "Resolving cookbooks for run list: #{expanded_run_list.inspect}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def cookbook_sync_start(cookbook_count)
|
31
|
+
puts 'Synchronizing cookbooks'
|
32
|
+
end
|
33
|
+
|
34
|
+
def synchronized_cookbook(cookbook_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def cookbook_sync_complete
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def library_load_start(file_count)
|
42
|
+
end
|
43
|
+
|
44
|
+
def file_loaded(path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def recipe_load_complete;
|
48
|
+
end
|
49
|
+
|
50
|
+
def converge_start(run_context)
|
51
|
+
end
|
52
|
+
|
53
|
+
def converge_complete;
|
54
|
+
end
|
55
|
+
|
56
|
+
def resource_skipped(resource, action, conditional)
|
57
|
+
end
|
58
|
+
|
59
|
+
def resource_up_to_date(resource, action)
|
60
|
+
end
|
61
|
+
|
62
|
+
def msg(message)
|
63
|
+
end
|
64
|
+
|
65
|
+
def resource_update_applied(resource, action, update)
|
66
|
+
@updates_by_resource[resource.name] << Array(update)[0]
|
67
|
+
end
|
68
|
+
|
69
|
+
def resource_updated(resource, action)
|
70
|
+
|
71
|
+
if resource.class == Chef::Resource::File ||
|
72
|
+
resource.class == Chef::Resource::Template ||
|
73
|
+
resource.class == Chef::Resource::CookbookFile
|
74
|
+
if resource.diff
|
75
|
+
print '=' * 80 + "\n"
|
76
|
+
ColorDiff.print_diff resource.diff.split('\n')
|
77
|
+
print '=' * 80 + "\n"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if resource.class == Chef::Resource::Package
|
82
|
+
print " \n"
|
83
|
+
if resource.version
|
84
|
+
print("* Install package #{resource.name} version #{resource.version} \n", :green)
|
85
|
+
else
|
86
|
+
print("* Remove package #{resource.name} \n", :red)
|
87
|
+
end
|
88
|
+
print " \n"
|
89
|
+
end
|
90
|
+
|
91
|
+
updated_resources << resource
|
92
|
+
end
|
93
|
+
|
94
|
+
def display_error(description)
|
95
|
+
puts('')
|
96
|
+
description.display(output)
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Очень хотим красивые fail
|
101
|
+
#
|
102
|
+
|
103
|
+
def registration_failed(node_name, exception, config)
|
104
|
+
description = ErrorMapper.registration_failed(node_name, exception, config)
|
105
|
+
display_error(description)
|
106
|
+
end
|
107
|
+
|
108
|
+
def node_load_failed(node_name, exception, config)
|
109
|
+
description = ErrorMapper.node_load_failed(node_name, exception, config)
|
110
|
+
display_error(description)
|
111
|
+
end
|
112
|
+
|
113
|
+
def run_list_expand_failed(node, exception)
|
114
|
+
description = ErrorMapper.run_list_expand_failed(node, exception)
|
115
|
+
display_error(description)
|
116
|
+
end
|
117
|
+
|
118
|
+
def cookbook_resolution_failed(expanded_run_list, exception)
|
119
|
+
description = ErrorMapper.cookbook_resolution_failed(expanded_run_list, exception)
|
120
|
+
display_error(description)
|
121
|
+
end
|
122
|
+
|
123
|
+
def cookbook_sync_failed(cookbooks, exception)
|
124
|
+
description = ErrorMapper.cookbook_sync_failed(cookbooks, exception)
|
125
|
+
display_error(description)
|
126
|
+
end
|
127
|
+
|
128
|
+
def resource_failed(resource, action, exception)
|
129
|
+
description = ErrorMapper.resource_failed(resource, action, exception)
|
130
|
+
display_error(description)
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Undev
|
2
|
+
class Handler < Chef::Handler
|
3
|
+
|
4
|
+
def report
|
5
|
+
begin
|
6
|
+
data = report_data
|
7
|
+
url = "/undevapi"
|
8
|
+
rest_client = Chef::REST.new(Chef::Config[:chef_server_url])
|
9
|
+
rest_client.post(url, data)
|
10
|
+
rescue Net::HTTPServerException => e
|
11
|
+
if e.response.code.to_s == "400"
|
12
|
+
Chef::FileCache.store("failed-reporting-data.json",
|
13
|
+
Chef::JSONCompat.to_json_pretty(data), 0640)
|
14
|
+
Chef::Log.debug("Failed to post reporting data to server (HTTP 400), saving to
|
15
|
+
#{Chef::FileCache.load("failed-reporting-data.json", false)}")
|
16
|
+
else
|
17
|
+
Chef::Log.error("Failed to post reporting data to server (HTTP #{e.response.code.to_s})")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def riemann_status
|
23
|
+
return 'ok' unless exception
|
24
|
+
'critical'
|
25
|
+
end
|
26
|
+
|
27
|
+
def report_data
|
28
|
+
data = {}
|
29
|
+
data[:node] = node.fqdn
|
30
|
+
data[:status] = riemann_status
|
31
|
+
data[:run_list] = @run_status.node.run_list.to_json
|
32
|
+
data[:start_time] = start_time.to_s
|
33
|
+
data[:end_time] = end_time.to_s
|
34
|
+
data[:message] = exception.message if exception
|
35
|
+
data[:tags] = node[:server_info_ng][:tags] if node[:server_info_ng]
|
36
|
+
data
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'chef/resource'
|
2
|
+
|
3
|
+
class Chef::Resource
|
4
|
+
|
5
|
+
def load_prior_resource
|
6
|
+
begin
|
7
|
+
prior_resource = run_context.resource_collection.lookup(self.to_s)
|
8
|
+
prior_resource.instance_variables.each do |iv|
|
9
|
+
unless iv.to_sym == :@source_line || iv.to_sym == :@action || iv.to_sym == :@not_if || iv.to_sym == :@only_if
|
10
|
+
self.instance_variable_set(iv, prior_resource.instance_variable_get(iv))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
true
|
14
|
+
rescue Chef::Exceptions::ResourceNotFound
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
$VERBOSE = nil
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ColorDiff
|
2
|
+
|
3
|
+
FILE_IN_R = /^\-\-\- /
|
4
|
+
FILE_OUT_R = /^\+\+\+ /
|
5
|
+
OUT_R = /^\-/
|
6
|
+
IN_R = /^\+/
|
7
|
+
|
8
|
+
$RESET = "\033[0m"
|
9
|
+
$BOLD = "\033[1m"
|
10
|
+
$BLINK = "\033[5m"
|
11
|
+
|
12
|
+
$BLACK = "\033[30m"
|
13
|
+
$RED = "\033[31m"
|
14
|
+
$GREEN = "\033[32m"
|
15
|
+
$BROWN = "\033[33m"
|
16
|
+
$BLUE = "\033[34m"
|
17
|
+
$MAGENTA = "\033[35m"
|
18
|
+
$CYAN = "\033[36m"
|
19
|
+
$WHITE = "\033[37m"
|
20
|
+
|
21
|
+
def self.print_diff(array)
|
22
|
+
array.each do |line|
|
23
|
+
line.chomp!
|
24
|
+
if line =~ FILE_IN_R
|
25
|
+
puts "#{$MAGENTA}" + line + "#{$RESET}"
|
26
|
+
elsif line =~ FILE_OUT_R
|
27
|
+
puts "#{$BLUE}" + line + "#{$RESET}"
|
28
|
+
elsif line =~ OUT_R
|
29
|
+
puts "#{$RED}" + line + "#{$RESET}"
|
30
|
+
elsif line =~ IN_R
|
31
|
+
puts "#{$GREEN}" + line + "#{$RESET}"
|
32
|
+
else
|
33
|
+
puts line
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/chef/undev.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-undev
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vasiliev Dmitry
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
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
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Chef client patches for undev
|
63
|
+
email:
|
64
|
+
- vadv.mkn@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- chef-undev.gemspec
|
75
|
+
- lib/chef/undev.rb
|
76
|
+
- lib/chef/undev/formatters/silent.rb
|
77
|
+
- lib/chef/undev/handler/reporter.rb
|
78
|
+
- lib/chef/undev/monkey_patches/load_prior_resource.rb
|
79
|
+
- lib/chef/undev/monkey_patches/verbose.rb
|
80
|
+
- lib/chef/undev/support/color_diff.rb
|
81
|
+
- lib/chef/undev/version.rb
|
82
|
+
homepage: http://git.undev.cc/megaadmins/chef-undev
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.23
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Silent formatters, handler report
|
107
|
+
test_files: []
|
108
|
+
has_rdoc:
|