knife-verschart 2.7.5 → 2.8.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/lib/chef/knife/Verschart.rb +268 -187
- metadata +2 -2
data/lib/chef/knife/Verschart.rb
CHANGED
|
@@ -19,6 +19,11 @@ module Verschart
|
|
|
19
19
|
:description => "A comma-separated list of environments to be considered primary. Versions which are NOT frozen willl be highlighted red.",
|
|
20
20
|
:proc => Proc.new { |primary| Chef::Config[:knife][:primary] = primary.split(',') }
|
|
21
21
|
|
|
22
|
+
option :html,
|
|
23
|
+
:long => "--html",
|
|
24
|
+
:description => "Output in basic html fomat.",
|
|
25
|
+
:proc => Proc.new { |html| Chef::Config[:knife][:html] = true }
|
|
26
|
+
|
|
22
27
|
option :envorder,
|
|
23
28
|
:short => "-o env[,env,....]",
|
|
24
29
|
:long => "--env_order env[,env,....]",
|
|
@@ -31,195 +36,271 @@ module Verschart
|
|
|
31
36
|
:proc => Proc.new { |cbselect| Chef::Config[:knife][:cbselect] = cbselect.split(',') }
|
|
32
37
|
|
|
33
38
|
def run
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
39
|
+
# Load Options
|
|
40
|
+
primary = config[:primary] || []
|
|
41
|
+
order = config[:envorder] || []
|
|
42
|
+
envorder = []
|
|
43
|
+
envorder = order.split(',') unless order.empty?
|
|
44
|
+
srv = server_url.sub(%r{https://}, '').sub(/:[0-9]*$/, '')
|
|
45
|
+
cbselect = config[:cbselect] || []
|
|
46
|
+
html = config[:html] || false
|
|
47
|
+
|
|
48
|
+
# Opening output
|
|
49
|
+
if html
|
|
50
|
+
ui.info('<!DOCTYPE html>')
|
|
51
|
+
ui.info('<html>')
|
|
52
|
+
ui.info('<body>')
|
|
53
|
+
ui.info('<p>Showing Versions for cs1chl001.classifiedventures.com')
|
|
54
|
+
ui.info('</BR>')
|
|
55
|
+
ui.info("Version numbers in the Latest column in <span style='color:blue'> blue</span> are frozen</BR>")
|
|
56
|
+
ui.info("Version numbers in the <span style='color:purple'><strong>primary</strong></span> Environment(s) which are NOT frozen will be <span style='background:yellow;color:red'>red</span></BR>")
|
|
57
|
+
ui.info("Version numbers which do not exist on the server will be in <span style='color:green'><strong>green</strong></span></BR>")
|
|
58
|
+
ui.info("Version numbers which are different from the Latest (but do exist), will be in <span style='background:blue;color:white'>white</span></BR>")
|
|
59
|
+
ui.info("Requested environment order is #{envorder}</BR>") unless envorder.empty?
|
|
60
|
+
ui.info('')
|
|
61
|
+
else
|
|
62
|
+
ui.info("Showing Versions for #{srv}")
|
|
63
|
+
ui.info('')
|
|
64
|
+
ui.info("Version numbers in the Latest column in " + "teal".teal + " are frozen")
|
|
65
|
+
ui.info("Version numbers in the " + "primary".purple + " Environment(s) which are NOT frozen will be " + "red".red ) unless primary.empty?
|
|
66
|
+
ui.info("Version numbers which do not exist on the server will be in " + "yellow".yellow)
|
|
67
|
+
ui.info("Version numbers which are different from the Latest (but do exist), will be in " + "blue".bold)
|
|
68
|
+
ui.info("Requested environment order is #{envorder}") unless envorder.empty?
|
|
69
|
+
ui.info('')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Build environment list and hash containing all constraints.
|
|
73
|
+
envis = [] # Placeholder for found environments
|
|
74
|
+
search_envs = Chef::Search::Query.new
|
|
75
|
+
qury = 'NOT name:_default'
|
|
76
|
+
|
|
77
|
+
search_envs.search('environment', qury) do |enviro|
|
|
78
|
+
envis << enviro.name
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
envs = [] # Final ordered list of Environments
|
|
82
|
+
unless envorder.empty?
|
|
83
|
+
envorder.each do |env|
|
|
84
|
+
if !envis.include?(env)
|
|
85
|
+
ui.warn "#{env} is not a valid environment!"
|
|
86
|
+
else
|
|
87
|
+
envs << env
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
envis.each do |env|
|
|
92
|
+
envs << env unless envs.include?(env)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# List of Chart headers
|
|
96
|
+
hdrs = ['Cookbooks', 'Latest'].concat(envs)
|
|
97
|
+
|
|
98
|
+
# counter for longest cookbook name
|
|
99
|
+
cblen = 10
|
|
100
|
+
|
|
101
|
+
charthash = Hash.new # The hash for all chart data
|
|
102
|
+
# store list of availible cookbook versions for comparison to constraint
|
|
103
|
+
vers_store = Chef::CookbookVersion.list_all_versions
|
|
104
|
+
|
|
105
|
+
# Load list of latest cookbook versions
|
|
106
|
+
charthash['Latest'] = Hash.new
|
|
107
|
+
charthash['Cookbooks'] = Hash.new
|
|
108
|
+
charthash['Latest']['col'] = 12
|
|
109
|
+
r = Regexp.union(cbselect)
|
|
110
|
+
server_side_cookbooks = Chef::CookbookVersion.list
|
|
111
|
+
server_side_cookbooks.each do |svcb|
|
|
112
|
+
select_match = false
|
|
113
|
+
if !cbselect.empty? && r =~ svcb[0]
|
|
114
|
+
select_match = true
|
|
115
|
+
end
|
|
116
|
+
if cbselect.empty? || select_match
|
|
117
|
+
fm = Chef::CookbookVersion.load(svcb[0])
|
|
118
|
+
cblen = fm.metadata.name.length if fm.metadata.name.length > cblen
|
|
119
|
+
charthash['Latest'][fm.metadata.name] = Hash.new(0)
|
|
120
|
+
charthash['Cookbooks'][fm.metadata.name] = Hash.new(0)
|
|
121
|
+
charthash['Latest'][fm.metadata.name]['vs'] = fm.metadata.version.to_s
|
|
122
|
+
charthash['Cookbooks'][fm.metadata.name]['vs'] = fm.metadata.name
|
|
123
|
+
if fm.frozen_version?
|
|
124
|
+
charthash['Latest'][fm.metadata.name]['teal'] = true
|
|
125
|
+
else
|
|
126
|
+
charthash['Latest'][fm.metadata.name]['teal'] = false
|
|
127
|
+
end
|
|
128
|
+
charthash['Latest'][fm.metadata.name]['bold'] = false
|
|
129
|
+
charthash['Latest'][fm.metadata.name]['red'] = false
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Set first column width
|
|
134
|
+
charthash['Cookbooks']['col'] = cblen + 2
|
|
135
|
+
|
|
136
|
+
# Load vers constraints
|
|
137
|
+
search_envs.search('environment', qury) do |enviro|
|
|
138
|
+
charthash[enviro.name] = Hash.new
|
|
139
|
+
if enviro.name.length > 8
|
|
140
|
+
charthash[enviro.name]['col'] = enviro.name.length + 2
|
|
141
|
+
else
|
|
142
|
+
charthash[enviro.name]['col'] = 10
|
|
143
|
+
end
|
|
144
|
+
enviro.cookbook_versions.each do | cb, v|
|
|
145
|
+
if charthash['Latest'].has_key?(cb)
|
|
146
|
+
charthash[enviro.name][cb] = Hash.new(0)
|
|
147
|
+
charthash[enviro.name][cb]['vs'] = v.to_s
|
|
148
|
+
vn = v.to_s.split(' ')[1]
|
|
149
|
+
charthash[enviro.name][cb]['red'] = false
|
|
150
|
+
charthash[enviro.name][cb]['teal'] = false
|
|
151
|
+
charthash[enviro.name][cb]['yellow'] = true
|
|
152
|
+
charthash[enviro.name][cb]['bold'] = false
|
|
153
|
+
vers_store[cb]['versions'].each do | vss |
|
|
154
|
+
if vss['version'] == vn
|
|
155
|
+
charthash[enviro.name][cb]['yellow'] = false
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
if !primary.empty? && primary.include?(enviro.name) && !charthash[enviro.name][cb]['yellow']
|
|
159
|
+
fm = Chef::CookbookVersion.load(cb, version = "#{vn}")
|
|
160
|
+
charthash[enviro.name][cb]['red'] = true unless fm.frozen_version?
|
|
161
|
+
end
|
|
162
|
+
if vn != charthash['Latest'][cb]['vs'] && !charthash[enviro.name][cb]['yellow']
|
|
163
|
+
charthash[enviro.name][cb]['bold'] = true
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
if html
|
|
170
|
+
### html format here!
|
|
171
|
+
print "<table border='1' style='width:75%;border-collapse:collapse;font-size:14px'>"
|
|
172
|
+
print("</tr>")
|
|
173
|
+
print("<tr>")
|
|
174
|
+
hdrs.each do | hdr |
|
|
175
|
+
if !primary.empty? && primary.include?(hdr)
|
|
176
|
+
print "<td style='color:purple'><strong>#{hdr.ljust(charthash[hdr]['col'])}</strong></td>\n"
|
|
177
|
+
else
|
|
178
|
+
print "<td><strong>#{hdr.ljust(charthash[hdr]['col'])}</strong></td>\n"
|
|
111
179
|
end
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
charthash[enviro.name][cb]['yellow'] = false
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
if !primary.empty? && primary.include?(enviro.name) && !charthash[enviro.name][cb]['yellow']
|
|
140
|
-
fm = Chef::CookbookVersion.load(cb, version = "#{vn}")
|
|
141
|
-
charthash[enviro.name][cb]['red'] = true unless fm.frozen_version?
|
|
142
|
-
end
|
|
143
|
-
if vn != charthash['Latest'][cb]['vs'] && !charthash[enviro.name][cb]['yellow']
|
|
144
|
-
charthash[enviro.name][cb]['bold'] = true
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
# Print the Chart headers
|
|
151
|
-
hdrs.each do | hdr |
|
|
152
|
-
if !primary.empty? && primary.include?(hdr)
|
|
153
|
-
print hdr.purple.ljust(charthash[hdr]['col'])
|
|
154
|
-
else
|
|
155
|
-
print hdr.ljust(charthash[hdr]['col'])
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
print "\n"
|
|
159
|
-
|
|
160
|
-
# Print the Chart data
|
|
161
|
-
charthash['Cookbooks'].keys.sort.each do | cbk |
|
|
162
|
-
unless cbk == 'col'
|
|
163
|
-
hdrs.each do | hdr |
|
|
164
|
-
case hdr
|
|
165
|
-
when 'Cookbooks'
|
|
166
|
-
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
|
|
167
|
-
when 'Latest'
|
|
168
|
-
if charthash[hdr][cbk]['teal']
|
|
169
|
-
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).teal
|
|
170
|
-
else
|
|
171
|
-
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
|
|
172
|
-
end
|
|
173
|
-
else
|
|
174
|
-
if charthash[hdr].has_key?(cbk)
|
|
175
|
-
if charthash[hdr][cbk]['bold']
|
|
176
|
-
if charthash[hdr][cbk]['red']
|
|
177
|
-
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red.bold
|
|
178
|
-
elsif charthash[hdr][cbk]['yellow']
|
|
179
|
-
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).yellow.bold
|
|
180
|
-
else
|
|
181
|
-
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).bold
|
|
182
|
-
end
|
|
180
|
+
end
|
|
181
|
+
print("</tr>\n")
|
|
182
|
+
|
|
183
|
+
# Print the Chart data
|
|
184
|
+
charthash['Cookbooks'].keys.sort.each do | cbk |
|
|
185
|
+
print("<tr>")
|
|
186
|
+
unless cbk == 'col'
|
|
187
|
+
hdrs.each do | hdr |
|
|
188
|
+
case hdr
|
|
189
|
+
when 'Cookbooks'
|
|
190
|
+
print "<td>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</td>\n"
|
|
191
|
+
when 'Latest'
|
|
192
|
+
if charthash[hdr][cbk]['teal']
|
|
193
|
+
print "<td style='color:blue'>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</td>\n"
|
|
194
|
+
else
|
|
195
|
+
print "<td>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</td>\n"
|
|
196
|
+
end
|
|
197
|
+
else
|
|
198
|
+
if charthash[hdr].has_key?(cbk)
|
|
199
|
+
if charthash[hdr][cbk]['bold']
|
|
200
|
+
if charthash[hdr][cbk]['red']
|
|
201
|
+
print "<td style='background:yellow;color:red'><strong>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</strong></td>\n"
|
|
202
|
+
elsif charthash[hdr][cbk]['yellow']
|
|
203
|
+
print "<td style='background:blue;color:green'><strong>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</strong></td>\n"
|
|
183
204
|
else
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
205
|
+
print "<td style='background:blue;color:white'><strong>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</strong></td>\n"
|
|
206
|
+
end
|
|
207
|
+
else
|
|
208
|
+
if charthash[hdr][cbk]['red']
|
|
209
|
+
print "<td style='background:yello;color:red'><strong>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</strong></td>\n"
|
|
210
|
+
elsif charthash[hdr][cbk]['yellow']
|
|
211
|
+
print "<td style='color:green'><strong>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</strong></td>\n"
|
|
212
|
+
else
|
|
213
|
+
print "<td>#{charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])}</td>\n"
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
else
|
|
217
|
+
print "<td>X</td>".ljust(charthash[hdr]['col'])
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
printf "</tr>\n"
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
print "</table>\n"
|
|
225
|
+
print "</body>\n"
|
|
226
|
+
print "</html>\n"
|
|
227
|
+
else
|
|
228
|
+
#### Old print format
|
|
229
|
+
# Print the Chart headers
|
|
230
|
+
hdrs.each do | hdr |
|
|
231
|
+
if !primary.empty? && primary.include?(hdr)
|
|
232
|
+
print hdr.purple.ljust(charthash[hdr]['col'])
|
|
233
|
+
else
|
|
234
|
+
print hdr.ljust(charthash[hdr]['col'])
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
print "\n"
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# Print the Chart data
|
|
241
|
+
charthash['Cookbooks'].keys.sort.each do | cbk |
|
|
242
|
+
unless cbk == 'col'
|
|
243
|
+
hdrs.each do | hdr |
|
|
244
|
+
case hdr
|
|
245
|
+
when 'Cookbooks'
|
|
246
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
|
|
247
|
+
when 'Latest'
|
|
248
|
+
if charthash[hdr][cbk]['teal']
|
|
249
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).teal
|
|
250
|
+
else
|
|
251
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
|
|
252
|
+
end
|
|
253
|
+
else
|
|
254
|
+
if charthash[hdr].has_key?(cbk)
|
|
255
|
+
if charthash[hdr][cbk]['bold']
|
|
256
|
+
if charthash[hdr][cbk]['red']
|
|
257
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red.bold
|
|
258
|
+
elsif charthash[hdr][cbk]['yellow']
|
|
259
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).yellow.bold
|
|
260
|
+
else
|
|
261
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).bold
|
|
262
|
+
end
|
|
263
|
+
else
|
|
264
|
+
if charthash[hdr][cbk]['red']
|
|
265
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red
|
|
266
|
+
elsif charthash[hdr][cbk]['yellow']
|
|
267
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).yellow
|
|
268
|
+
else
|
|
269
|
+
print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
else
|
|
273
|
+
print "X".ljust(charthash[hdr]['col'])
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
printf "\n"
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
if cbselect.empty?
|
|
282
|
+
# Look for obsolete constraints
|
|
283
|
+
hd = 0 # Flag for section header
|
|
284
|
+
ev = 0 # Flag for Environent header
|
|
285
|
+
|
|
286
|
+
envs.each do |env|
|
|
287
|
+
charthash[env].keys.each do |ckbk|
|
|
288
|
+
unless charthash['Cookbooks'].has_key?(ckbk)
|
|
289
|
+
unless hd == 1
|
|
290
|
+
ui.info('')
|
|
291
|
+
ui.info('Obsolete Version constraints are listed below')
|
|
292
|
+
hd = 1
|
|
293
|
+
end
|
|
294
|
+
unless ev == 1
|
|
295
|
+
ui.info('')
|
|
296
|
+
ui.info(env)
|
|
297
|
+
end
|
|
298
|
+
ui.info("-- #{ckbk} #{charthash[env][ckbk]['vs']}")
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
end
|
|
223
304
|
end
|
|
224
305
|
end
|
|
225
306
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: knife-verschart
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.8.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description:
|
|
15
15
|
email: chazzly@gmail.com
|