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.
Files changed (2) hide show
  1. data/lib/chef/knife/Verschart.rb +268 -187
  2. metadata +2 -2
@@ -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
- # Load Options
35
- primary = config[:primary] || []
36
- order = config[:envorder] || []
37
- envorder = []
38
- envorder = order.split(',') unless order.empty?
39
- srv = server_url.sub(%r{https://}, '').sub(/:[0-9]*$/, '')
40
- cbselect = config[:cbselect] || []
41
-
42
- # Opening output
43
- ui.info('')
44
- ui.info("Showing Versions for #{srv}")
45
- ui.info('')
46
- ui.info("Version numbers in the Latest column in " + "teal".teal + " are frozen")
47
- ui.info("Version numbers in the " + "primary".purple + " Environment(s) which are NOT frozen will be " + "red".red ) unless primary.empty?
48
- ui.info("Version numbers which do not exist on the server will be in " + "yellow".yellow)
49
- ui.info("Version numbers which are different from the Latest (but do exist), will be in " + "blue".bold)
50
- ui.info("Requested environment order is #{envorder}") unless envorder.empty?
51
- ui.info('')
52
-
53
- # Build environment list and hash containing all constraints.
54
- envis = [] # Placeholder for found environments
55
- search_envs = Chef::Search::Query.new
56
- qury = 'NOT name:_default'
57
-
58
- search_envs.search('environment', qury) do |enviro|
59
- envis << enviro.name
60
- end
61
-
62
- envs = [] # Final ordered list of Environments
63
- unless envorder.empty?
64
- envorder.each do |env|
65
- if !envis.include?(env)
66
- ui.warn "#{env} is not a valid environment!"
67
- else
68
- envs << env
69
- end
70
- end
71
- end
72
- envis.each do |env|
73
- envs << env unless envs.include?(env)
74
- end
75
-
76
- # List of Chart headers
77
- hdrs = ['Cookbooks', 'Latest'].concat(envs)
78
-
79
- # counter for longest cookbook name
80
- cblen = 10
81
-
82
- charthash = Hash.new # The hash for all chart data
83
- # store list of availible cookbook versions for comparison to constraint
84
- vers_store = Chef::CookbookVersion.list_all_versions
85
-
86
- # Load list of latest cookbook versions
87
- charthash['Latest'] = Hash.new
88
- charthash['Cookbooks'] = Hash.new
89
- charthash['Latest']['col'] = 12
90
- r = Regexp.union(cbselect)
91
- server_side_cookbooks = Chef::CookbookVersion.list
92
- server_side_cookbooks.each do |svcb|
93
- select_match = false
94
- if !cbselect.empty? && r =~ svcb[0]
95
- select_match = true
96
- end
97
- if cbselect.empty? || select_match
98
- fm = Chef::CookbookVersion.load(svcb[0])
99
- cblen = fm.metadata.name.length if fm.metadata.name.length > cblen
100
- charthash['Latest'][fm.metadata.name] = Hash.new(0)
101
- charthash['Cookbooks'][fm.metadata.name] = Hash.new(0)
102
- charthash['Latest'][fm.metadata.name]['vs'] = fm.metadata.version.to_s
103
- charthash['Cookbooks'][fm.metadata.name]['vs'] = fm.metadata.name
104
- if fm.frozen_version?
105
- charthash['Latest'][fm.metadata.name]['teal'] = true
106
- else
107
- charthash['Latest'][fm.metadata.name]['teal'] = false
108
- end
109
- charthash['Latest'][fm.metadata.name]['bold'] = false
110
- charthash['Latest'][fm.metadata.name]['red'] = false
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
- end
113
-
114
- # Set first column width
115
- charthash['Cookbooks']['col'] = cblen + 2
116
-
117
- # Load vers constraints
118
- search_envs.search('environment', qury) do |enviro|
119
- charthash[enviro.name] = Hash.new
120
- if enviro.name.length > 8
121
- charthash[enviro.name]['col'] = enviro.name.length + 2
122
- else
123
- charthash[enviro.name]['col'] = 10
124
- end
125
- enviro.cookbook_versions.each do | cb, v|
126
- if charthash['Latest'].has_key?(cb)
127
- charthash[enviro.name][cb] = Hash.new(0)
128
- charthash[enviro.name][cb]['vs'] = v.to_s
129
- vn = v.to_s.split(' ')[1]
130
- charthash[enviro.name][cb]['red'] = false
131
- charthash[enviro.name][cb]['teal'] = false
132
- charthash[enviro.name][cb]['yellow'] = true
133
- charthash[enviro.name][cb]['bold'] = false
134
- vers_store[cb]['versions'].each do | vss |
135
- if vss['version'] == vn
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
- if charthash[hdr][cbk]['red']
185
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red
186
- elsif charthash[hdr][cbk]['yellow']
187
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).yellow
188
- else
189
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
190
- end
191
- end
192
- else
193
- print "X".ljust(charthash[hdr]['col'])
194
- end
195
- end
196
- end
197
- printf "\n"
198
- end
199
- end
200
-
201
- if cbselect.empty?
202
- # Look for obsolete constraints
203
- hd = 0 # Flag for section header
204
- ev = 0 # Flag for Environent header
205
-
206
- envs.each do |env|
207
- charthash[env].keys.each do |ckbk|
208
- unless charthash['Cookbooks'].has_key?(ckbk)
209
- unless hd == 1
210
- ui.info('')
211
- ui.info('Obsolete Version constraints are listed below')
212
- hd = 1
213
- end
214
- unless ev == 1
215
- ui.info('')
216
- ui.info(env)
217
- end
218
- ui.info("-- #{ckbk} #{charthash[env][ckbk]['vs']}")
219
- end
220
- end
221
- end
222
- end
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.7.5
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: 2014-10-09 00:00:00.000000000 Z
12
+ date: 2015-02-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: chazzly@gmail.com