knife-tidy 0.2.4 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/conf/substitutions.json.example +13 -1
- data/lib/chef/knife/tidy_backup_clean.rb +17 -4
- data/lib/chef/knife/tidy_server_clean.rb +18 -4
- data/lib/chef/tidy_substitutions.rb +3 -3
- data/lib/knife-tidy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz: '
|
3
|
+
metadata.gz: b7f8cd82c1128a57a08b0f4d566b6f4c0fab57e0
|
4
|
+
data.tar.gz: '00768c3e853bb6bdbde3d183f84094a933e6b08f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10ae87a0e2bc3248cc63aa67817e61567ea631df7bb5e644947e97aae7f43db29c3bfec3ef7f78ab4e52aeaf5f690d2d03d1d51bd5e3d41646083eecd1895eb1
|
7
|
+
data.tar.gz: 9719b04e58c3c9227a6c2839bbb3e0b02e21487885fcb94f7c20a15d5279754c431cff97f4988fa369b4e42710cb6b004c7f4ea898f34db565170971283df5c2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.1.0](https://github.com/chef-customers/knife-tidy/tree/0.1.0) (2017-09-14)
|
4
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.2.4...0.1.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- FATAL: Cannot find subcommand for: 'tidy backup clean' [\#12](https://github.com/chef-customers/knife-tidy/issues/12)
|
9
|
+
|
10
|
+
**Merged pull requests:**
|
11
|
+
|
12
|
+
- bump to 0.3.0 [\#19](https://github.com/chef-customers/knife-tidy/pull/19) ([jeremymv2](https://github.com/jeremymv2))
|
13
|
+
- added dry-run to server clean [\#18](https://github.com/chef-customers/knife-tidy/pull/18) ([jeremymv2](https://github.com/jeremymv2))
|
14
|
+
|
3
15
|
## [0.2.4](https://github.com/chef-customers/knife-tidy/tree/0.2.4) (2017-09-12)
|
4
16
|
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.2.3...0.2.4)
|
5
17
|
|
@@ -3,12 +3,24 @@
|
|
3
3
|
"organizations/*/cookbooks/chef-sugar*/metadata.rb":[
|
4
4
|
{
|
5
5
|
"pattern":"^require .*/lib/chef/sugar/version",
|
6
|
-
"replace":"# require File.expand_path('../lib/chef/sugar/version', __FILE__)"
|
6
|
+
"replace":"# require File.expand_path('../lib/chef/sugar/version', *__FILE__)"
|
7
7
|
},
|
8
8
|
{
|
9
9
|
"pattern":"version *Chef::Sugar::VERSION",
|
10
10
|
"replace":"version !COOKBOOK_VERSION!"
|
11
11
|
}
|
12
12
|
]
|
13
|
+
},
|
14
|
+
"io-read-version-and-readme.md":{
|
15
|
+
"organizations/*/cookbooks/*/metadata.rb":[
|
16
|
+
{
|
17
|
+
"pattern":"^version +IO.read.* 'VERSION'.*",
|
18
|
+
"replace":"version !COOKBOOK_VERSION!"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"pattern":"^long_description +IO.read.* 'README.md'.*",
|
22
|
+
"replace":"#long_description \"A Long Description..\""
|
23
|
+
}
|
24
|
+
]
|
13
25
|
}
|
14
26
|
}
|
@@ -10,6 +10,7 @@ class Chef
|
|
10
10
|
require 'chef/tidy_substitutions'
|
11
11
|
require 'chef/tidy_acls'
|
12
12
|
require 'ffi_yajl'
|
13
|
+
require 'fileutils'
|
13
14
|
end
|
14
15
|
|
15
16
|
banner "knife tidy backup clean (OPTIONS)"
|
@@ -25,6 +26,7 @@ class Chef
|
|
25
26
|
:description => 'The path to the file used for substitutions. If non-existant, a boiler plate one will be created.'
|
26
27
|
|
27
28
|
def run
|
29
|
+
|
28
30
|
unless config[:backup_path] && ::File.directory?(config[:backup_path])
|
29
31
|
ui.error 'Must specify valid --backup-path'
|
30
32
|
exit 1
|
@@ -47,8 +49,8 @@ class Chef
|
|
47
49
|
org_acls.validate_user_acls
|
48
50
|
fix_self_dependencies(org)
|
49
51
|
fix_cookbook_names(org)
|
50
|
-
load_cookbooks(org)
|
51
52
|
generate_new_metadata(org)
|
53
|
+
load_cookbooks(org)
|
52
54
|
end
|
53
55
|
|
54
56
|
completion_message
|
@@ -106,13 +108,12 @@ class Chef
|
|
106
108
|
puts "INFO: Loading #{cookbook}"
|
107
109
|
ret = cl.load_cookbook(cookbook)
|
108
110
|
if ret.nil?
|
109
|
-
|
111
|
+
action_needed("ACTION NEEDED: Something's wrong with the #{cookbook} cookbook - cannot load it! Moving to cookbooks.broken folder.")
|
110
112
|
broken_cookooks_add(org, cookbook)
|
111
113
|
end
|
112
114
|
end
|
113
115
|
rescue LoadError => e
|
114
116
|
ui.error e
|
115
|
-
puts 'ACTION NEEDED: Look at the cookbook above and determine what in the metadata.rb is causing the exception and rectify manually'
|
116
117
|
exit 1
|
117
118
|
end
|
118
119
|
|
@@ -168,7 +169,9 @@ class Chef
|
|
168
169
|
end
|
169
170
|
|
170
171
|
def substitutions_file
|
171
|
-
|
172
|
+
sub_file_path = ::File.expand_path(config[:gsub_file])
|
173
|
+
ui.error "Subtitutions file #{sub_file_path} does not exist!" unless ::File.exist?(sub_file_path)
|
174
|
+
@substitutions_file ||= sub_file_path
|
172
175
|
end
|
173
176
|
|
174
177
|
def orgs
|
@@ -195,6 +198,16 @@ class Chef
|
|
195
198
|
yield cookbook
|
196
199
|
end
|
197
200
|
end
|
201
|
+
|
202
|
+
def action_needed_file_path
|
203
|
+
::File.expand_path('knife-tidy-actions-needed.txt')
|
204
|
+
end
|
205
|
+
|
206
|
+
def action_needed(msg)
|
207
|
+
::File.open(action_needed_file_path, 'a') do |f|
|
208
|
+
f.write(msg)
|
209
|
+
end
|
210
|
+
end
|
198
211
|
end
|
199
212
|
end
|
200
213
|
end
|
@@ -26,6 +26,10 @@ class Chef
|
|
26
26
|
:long => '--only-nodes',
|
27
27
|
:description => 'Only delete stale nodes from Chef Server.'
|
28
28
|
|
29
|
+
option :dry_run,
|
30
|
+
:long => '--dry-run',
|
31
|
+
:description => 'Do not perform any actual deletion, only report on what would have been deleted.'
|
32
|
+
|
29
33
|
def run
|
30
34
|
# not enabled
|
31
35
|
ui.warn "This feature is not enabled"
|
@@ -34,9 +38,9 @@ class Chef
|
|
34
38
|
STDOUT.sync = true
|
35
39
|
|
36
40
|
ensure_reports_dir
|
37
|
-
|
41
|
+
puts "INFO: Reading from #{tidy.reports_dir} directory"
|
38
42
|
|
39
|
-
|
43
|
+
puts "INFO: Using thread concurrency #{config[:concurrency]}"
|
40
44
|
configure_chef
|
41
45
|
|
42
46
|
if config[:only_cookbooks] && config[:only_nodes]
|
@@ -64,7 +68,7 @@ class Chef
|
|
64
68
|
queue = Chef::Util::ThreadedJobQueue.new
|
65
69
|
unused_cookbooks_file = ::File.join(tidy.reports_dir, "#{org}_unused_cookbooks.json")
|
66
70
|
return unless ::File.exist?(unused_cookbooks_file)
|
67
|
-
|
71
|
+
puts "INFO: Cleaning cookbooks for Org: #{org}, using #{unused_cookbooks_file}"
|
68
72
|
unused_cookbooks = FFI_Yajl::Parser.parse(::File.read(unused_cookbooks_file), symbolize_names: true)
|
69
73
|
unused_cookbooks.keys.each do |cookbook|
|
70
74
|
versions = unused_cookbooks[cookbook]
|
@@ -77,11 +81,16 @@ class Chef
|
|
77
81
|
|
78
82
|
def delete_cookbook_job(org, cookbook, version)
|
79
83
|
path = "/organizations/#{org}/cookbooks/#{cookbook}/#{version}"
|
84
|
+
if config[:dry_run]
|
85
|
+
printf("INFO: Would have executed `rest.delete(#{path})`\n")
|
86
|
+
return
|
87
|
+
end
|
80
88
|
rest.delete(path)
|
81
89
|
response = '200'
|
82
90
|
rescue Net::HTTPServerException
|
83
91
|
response = $!.response.code
|
84
92
|
ensure
|
93
|
+
return if config[:dry_run]
|
85
94
|
formatted = response == '200' ?
|
86
95
|
ui.color(' Deleting %-20s %-10s %10s', :green) :
|
87
96
|
ui.color(' Deleting %-20s %-10s %10s', :red)
|
@@ -92,7 +101,7 @@ class Chef
|
|
92
101
|
queue = Chef::Util::ThreadedJobQueue.new
|
93
102
|
stale_nodes_file = ::File.join(tidy.reports_dir, "#{org}_stale_nodes.json")
|
94
103
|
return unless ::File.exist?(stale_nodes_file)
|
95
|
-
|
104
|
+
puts "INFO: Cleaning stale nodes for Org: #{org}, using #{stale_nodes_file}"
|
96
105
|
stale_nodes = FFI_Yajl::Parser.parse(::File.read(stale_nodes_file), symbolize_names: true)
|
97
106
|
stale_nodes[:list].each do |node|
|
98
107
|
queue << lambda { delete_node_job(org, node) }
|
@@ -102,11 +111,16 @@ class Chef
|
|
102
111
|
|
103
112
|
def delete_node_job(org, node)
|
104
113
|
path = "/organizations/#{org}/nodes/#{node}"
|
114
|
+
if config[:dry_run]
|
115
|
+
printf("INFO: Would have executed `rest.delete(#{path})`\n")
|
116
|
+
return
|
117
|
+
end
|
105
118
|
rest.delete(path)
|
106
119
|
response = '200'
|
107
120
|
rescue Net::HTTPServerException
|
108
121
|
response = $!.response.code
|
109
122
|
ensure
|
123
|
+
return if config[:dry_run]
|
110
124
|
formatted = response == '200' ?
|
111
125
|
ui.color(' Deleting %-20s %10s', :green) :
|
112
126
|
ui.color(' Deleting %-20s %10s', :red)
|
@@ -15,7 +15,7 @@ class Chef
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def load_data
|
18
|
-
|
18
|
+
puts "INFO: Loading substitutions from #{file_path}"
|
19
19
|
@data = FFI_Yajl::Parser.parse(::File.read(@file_path), symbolize_names: false)
|
20
20
|
rescue Errno::ENOENT
|
21
21
|
raise NoSubstitutionFile, file_path
|
@@ -42,7 +42,7 @@ class Chef
|
|
42
42
|
file.each_line do |line|
|
43
43
|
if line.match(search)
|
44
44
|
temp_file.puts replace
|
45
|
-
|
45
|
+
puts "INFO: ++ #{path}"
|
46
46
|
else
|
47
47
|
temp_file.puts line
|
48
48
|
end
|
@@ -61,7 +61,7 @@ class Chef
|
|
61
61
|
load_data
|
62
62
|
@data.keys.each do |entry|
|
63
63
|
@data[entry].keys.each do |glob|
|
64
|
-
|
64
|
+
puts "INFO: Running substitutions for #{entry} -> #{glob}"
|
65
65
|
Dir[::File.join(@backup_path, glob)].each do |file|
|
66
66
|
@data[entry][glob].each do |substitution|
|
67
67
|
search = Regexp.new(substitution['pattern'])
|
data/lib/knife-tidy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-tidy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|