knife-verschart 2.7.1 → 2.7.2

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 +197 -197
  2. metadata +3 -4
@@ -1,197 +1,197 @@
1
- ## Ver 2.5
2
- require 'chef/knife'
3
- require 'chef/search/query'
4
-
5
- class String
6
- def red; "\033[31m#{self}\033[0m" end
7
- def purple; "\033[35m#{self}\033[0m" end
8
- def teal; "\033[36m#{self}\033[0m" end
9
- def bold; "\033[44m\033[1m#{self}\033[0m" end # Bold & blue back-ground
10
- end
11
-
12
- module Verschart
13
- class Verschart < Chef::Knife
14
- banner 'knife verschart [-e env[,env,...]] [[-o| --env_order] env[,env,...]]'
15
-
16
- option :primary,
17
- :short => "-e env[,env,...]",
18
- :description => "A comma-separated list of environments to be considered primary. Versions which are NOT frozen willl be highlighted red.",
19
- :proc => Proc.new { |primary| Chef::Config[:knife][:primary] = primary.split(',') }
20
-
21
- option :envorder,
22
- :short => "-o env[,env,....]",
23
- :long => "--env_order env[,env,....]",
24
- :description => "A comma-separated list of environments to establish an display order. Any existing environments not included in this list will be added at the end",
25
- :proc => Proc.new { |envorder| Chef::Config[:knife][:envorder] = envorder.split(',') }
26
-
27
- def run
28
- # Load Options
29
- primary = config[:primary] || []
30
- order = config[:envorder] || []
31
- envorder = []
32
- envorder = order.split(',') unless order.empty?
33
- srv = server_url.sub(%r{https://}, '').sub(/:[0-9]*$/, '')
34
-
35
- # Opening output
36
- ui.info('')
37
- ui.info("Showing Versions for #{srv}")
38
- ui.info('')
39
- ui.info("Version numbers in the Latest column in " + "teal".teal + " are frozen")
40
- ui.info("Version numbers in the " + "primary".purple + " Environment(s) which are NOT frozen will be " + "red".red ) unless primary.empty?
41
- ui.info("Version numbers which are different from the Latest, will be in " + "blue".bold)
42
- ui.info("Requested environment order is #{envorder}") unless envorder.empty?
43
- ui.info('')
44
-
45
- # Build environment list and hash containing all constraints.
46
- envis = [] # Placeholder for found environments
47
- search_envs = Chef::Search::Query.new
48
- qury = 'NOT name:_default'
49
-
50
- search_envs.search('environment', qury) do |enviro|
51
- envis << enviro.name
52
- end
53
-
54
- envs = [] # Final ordered list of Environments
55
- unless envorder.empty?
56
- envorder.each do |env|
57
- if !envis.include?(env)
58
- ui.warn "#{env} is not a valid environment!"
59
- else
60
- envs << env
61
- end
62
- end
63
- end
64
- envis.each do |env|
65
- envs << env unless envs.include?(env)
66
- end
67
-
68
- # List of Chart headers
69
- hdrs = ['Cookbooks', 'Latest'].concat(envs)
70
-
71
- # counter for longest cookbook name
72
- cblen = 10
73
-
74
- charthash = Hash.new # The hash for all chart data
75
-
76
- # Load list of latest cookbook versions
77
- charthash['Latest'] = Hash.new
78
- charthash['Cookbooks'] = Hash.new
79
- charthash['Latest']['col'] = 12
80
- server_side_cookbooks = Chef::CookbookVersion.latest_cookbooks
81
- server_side_cookbooks.each do |svcb|
82
- fm = Chef::CookbookVersion.load(svcb[0], version = '_latest')
83
- cblen = fm.metadata.name.length if fm.metadata.name.length > cblen
84
- charthash['Latest'][fm.metadata.name] = Hash.new(0)
85
- charthash['Cookbooks'][fm.metadata.name] = Hash.new(0)
86
- charthash['Latest'][fm.metadata.name]['vs'] = fm.metadata.version.to_s
87
- charthash['Cookbooks'][fm.metadata.name]['vs'] = fm.metadata.name
88
- if fm.frozen_version?
89
- charthash['Latest'][fm.metadata.name]['teal'] = true
90
- else
91
- charthash['Latest'][fm.metadata.name]['teal'] = false
92
- end
93
- charthash['Latest'][fm.metadata.name]['bold'] = false
94
- charthash['Latest'][fm.metadata.name]['red'] = false
95
- end
96
-
97
- # Set first column width
98
- charthash['Cookbooks']['col'] = cblen + 2
99
-
100
- # Load vers constraints
101
- search_envs.search('environment', qury) do |enviro|
102
- charthash[enviro.name] = Hash.new
103
- if enviro.name.length > 8
104
- charthash[enviro.name]['col'] = enviro.name.length + 2
105
- else
106
- charthash[enviro.name]['col'] = 10
107
- end
108
- enviro.cookbook_versions.each do | cb, v|
109
- charthash[enviro.name][cb] = Hash.new(0)
110
- charthash[enviro.name][cb]['vs'] = v.to_s
111
- vn = v.to_s.split(' ')[1]
112
- charthash[enviro.name][cb]['red'] = false
113
- charthash[enviro.name][cb]['teal'] = false
114
- if charthash['Latest'].has_key?(cb)
115
- if !primary.empty? && primary.include?(enviro.name)
116
- fm = Chef::CookbookVersion.load(cb, version = "#{vn}")
117
- charthash[enviro.name][cb]['red'] = true unless fm.frozen_version?
118
- end
119
- if vn != charthash['Latest'][cb]['vs']
120
- charthash[enviro.name][cb]['bold'] = true
121
- else
122
- charthash[enviro.name][cb]['bold'] = false
123
- end
124
- end
125
- end
126
- end
127
-
128
- # Print the Chart headers
129
- hdrs.each do | hdr |
130
- if !primary.empty? && primary.include?(hdr)
131
- print hdr.purple.ljust(charthash[hdr]['col'])
132
- else
133
- print hdr.ljust(charthash[hdr]['col'])
134
- end
135
- end
136
- print "\n"
137
-
138
- # Print the Chart data
139
- charthash['Cookbooks'].keys.each do | cbk |
140
- unless cbk == 'col'
141
- hdrs.each do | hdr |
142
- case hdr
143
- when 'Cookbooks'
144
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
145
- when 'Latest'
146
- if charthash[hdr][cbk]['teal']
147
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).teal
148
- else
149
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
150
- end
151
- else
152
- if charthash[hdr].has_key?(cbk)
153
- if charthash[hdr][cbk]['bold']
154
- if charthash[hdr][cbk]['red']
155
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red.bold
156
- else
157
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).bold
158
- end
159
- else
160
- if charthash[hdr][cbk]['red']
161
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red
162
- else
163
- print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
164
- end
165
- end
166
- else
167
- print "X".ljust(charthash[hdr]['col'])
168
- end
169
- end
170
- end
171
- end
172
- printf "\n"
173
- end
174
-
175
- # Look for obsolete constraints
176
- hd = 0 # Flag for section header
177
- ev = 0 # Flag for Environent header
178
-
179
- envs.each do |env|
180
- charthash[env].keys.each do |ckbk|
181
- unless charthash['Cookbooks'].has_key?(ckbk)
182
- unless hd == 1
183
- ui.info('')
184
- ui.info('Obsolete Version constraints are listed below')
185
- hd = 1
186
- end
187
- unless ev == 1
188
- ui.info('')
189
- ui.info(env)
190
- end
191
- ui.info("-- #{ckbk} #{charthash[env][ckbk]['vs']}")
192
- end
193
- end
194
- end
195
- end
196
- end
197
- end
1
+ ## Ver 2.7.2
2
+ require 'chef/knife'
3
+ require 'chef/search/query'
4
+
5
+ class String
6
+ def red; "\033[31m#{self}\033[0m" end
7
+ def purple; "\033[35m#{self}\033[0m" end
8
+ def teal; "\033[36m#{self}\033[0m" end
9
+ def bold; "\033[44m\033[1m#{self}\033[0m" end # Bold & blue back-ground
10
+ end
11
+
12
+ module Verschart
13
+ class Verschart < Chef::Knife
14
+ banner 'knife verschart [-e env[,env,...]] [[-o| --env_order] env[,env,...]]'
15
+
16
+ option :primary,
17
+ :short => "-e env[,env,...]",
18
+ :description => "A comma-separated list of environments to be considered primary. Versions which are NOT frozen willl be highlighted red.",
19
+ :proc => Proc.new { |primary| Chef::Config[:knife][:primary] = primary.split(',') }
20
+
21
+ option :envorder,
22
+ :short => "-o env[,env,....]",
23
+ :long => "--env_order env[,env,....]",
24
+ :description => "A comma-separated list of environments to establish an display order. Any existing environments not included in this list will be added at the end",
25
+ :proc => Proc.new { |envorder| Chef::Config[:knife][:envorder] = envorder.split(',') }
26
+
27
+ def run
28
+ # Load Options
29
+ primary = config[:primary] || []
30
+ order = config[:envorder] || []
31
+ envorder = []
32
+ envorder = order.split(',') unless order.empty?
33
+ srv = server_url.sub(%r{https://}, '').sub(/:[0-9]*$/, '')
34
+
35
+ # Opening output
36
+ ui.info('')
37
+ ui.info("Showing Versions for #{srv}")
38
+ ui.info('')
39
+ ui.info("Version numbers in the Latest column in " + "teal".teal + " are frozen")
40
+ ui.info("Version numbers in the " + "primary".purple + " Environment(s) which are NOT frozen will be " + "red".red ) unless primary.empty?
41
+ ui.info("Version numbers which are different from the Latest, will be in " + "blue".bold)
42
+ ui.info("Requested environment order is #{envorder}") unless envorder.empty?
43
+ ui.info('')
44
+
45
+ # Build environment list and hash containing all constraints.
46
+ envis = [] # Placeholder for found environments
47
+ search_envs = Chef::Search::Query.new
48
+ qury = 'NOT name:_default'
49
+
50
+ search_envs.search('environment', qury) do |enviro|
51
+ envis << enviro.name
52
+ end
53
+
54
+ envs = [] # Final ordered list of Environments
55
+ unless envorder.empty?
56
+ envorder.each do |env|
57
+ if !envis.include?(env)
58
+ ui.warn "#{env} is not a valid environment!"
59
+ else
60
+ envs << env
61
+ end
62
+ end
63
+ end
64
+ envis.each do |env|
65
+ envs << env unless envs.include?(env)
66
+ end
67
+
68
+ # List of Chart headers
69
+ hdrs = ['Cookbooks', 'Latest'].concat(envs)
70
+
71
+ # counter for longest cookbook name
72
+ cblen = 10
73
+
74
+ charthash = Hash.new # The hash for all chart data
75
+
76
+ # Load list of latest cookbook versions
77
+ charthash['Latest'] = Hash.new
78
+ charthash['Cookbooks'] = Hash.new
79
+ charthash['Latest']['col'] = 12
80
+ server_side_cookbooks = Chef::CookbookVersion.list
81
+ server_side_cookbooks.each do |svcb|
82
+ fm = Chef::CookbookVersion.load(svcb[0])
83
+ cblen = fm.metadata.name.length if fm.metadata.name.length > cblen
84
+ charthash['Latest'][fm.metadata.name] = Hash.new(0)
85
+ charthash['Cookbooks'][fm.metadata.name] = Hash.new(0)
86
+ charthash['Latest'][fm.metadata.name]['vs'] = fm.metadata.version.to_s
87
+ charthash['Cookbooks'][fm.metadata.name]['vs'] = fm.metadata.name
88
+ if fm.frozen_version?
89
+ charthash['Latest'][fm.metadata.name]['teal'] = true
90
+ else
91
+ charthash['Latest'][fm.metadata.name]['teal'] = false
92
+ end
93
+ charthash['Latest'][fm.metadata.name]['bold'] = false
94
+ charthash['Latest'][fm.metadata.name]['red'] = false
95
+ end
96
+
97
+ # Set first column width
98
+ charthash['Cookbooks']['col'] = cblen + 2
99
+
100
+ # Load vers constraints
101
+ search_envs.search('environment', qury) do |enviro|
102
+ charthash[enviro.name] = Hash.new
103
+ if enviro.name.length > 8
104
+ charthash[enviro.name]['col'] = enviro.name.length + 2
105
+ else
106
+ charthash[enviro.name]['col'] = 10
107
+ end
108
+ enviro.cookbook_versions.each do | cb, v|
109
+ charthash[enviro.name][cb] = Hash.new(0)
110
+ charthash[enviro.name][cb]['vs'] = v.to_s
111
+ vn = v.to_s.split(' ')[1]
112
+ charthash[enviro.name][cb]['red'] = false
113
+ charthash[enviro.name][cb]['teal'] = false
114
+ if charthash['Latest'].has_key?(cb)
115
+ if !primary.empty? && primary.include?(enviro.name)
116
+ fm = Chef::CookbookVersion.load(cb, version = "#{vn}")
117
+ charthash[enviro.name][cb]['red'] = true unless fm.frozen_version?
118
+ end
119
+ if vn != charthash['Latest'][cb]['vs']
120
+ charthash[enviro.name][cb]['bold'] = true
121
+ else
122
+ charthash[enviro.name][cb]['bold'] = false
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ # Print the Chart headers
129
+ hdrs.each do | hdr |
130
+ if !primary.empty? && primary.include?(hdr)
131
+ print hdr.purple.ljust(charthash[hdr]['col'])
132
+ else
133
+ print hdr.ljust(charthash[hdr]['col'])
134
+ end
135
+ end
136
+ print "\n"
137
+
138
+ # Print the Chart data
139
+ charthash['Cookbooks'].keys.each do | cbk |
140
+ unless cbk == 'col'
141
+ hdrs.each do | hdr |
142
+ case hdr
143
+ when 'Cookbooks'
144
+ print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
145
+ when 'Latest'
146
+ if charthash[hdr][cbk]['teal']
147
+ print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).teal
148
+ else
149
+ print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
150
+ end
151
+ else
152
+ if charthash[hdr].has_key?(cbk)
153
+ if charthash[hdr][cbk]['bold']
154
+ if charthash[hdr][cbk]['red']
155
+ print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red.bold
156
+ else
157
+ print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).bold
158
+ end
159
+ else
160
+ if charthash[hdr][cbk]['red']
161
+ print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col']).red
162
+ else
163
+ print charthash[hdr][cbk]['vs'].ljust(charthash[hdr]['col'])
164
+ end
165
+ end
166
+ else
167
+ print "X".ljust(charthash[hdr]['col'])
168
+ end
169
+ end
170
+ end
171
+ end
172
+ printf "\n"
173
+ end
174
+
175
+ # Look for obsolete constraints
176
+ hd = 0 # Flag for section header
177
+ ev = 0 # Flag for Environent header
178
+
179
+ envs.each do |env|
180
+ charthash[env].keys.each do |ckbk|
181
+ unless charthash['Cookbooks'].has_key?(ckbk)
182
+ unless hd == 1
183
+ ui.info('')
184
+ ui.info('Obsolete Version constraints are listed below')
185
+ hd = 1
186
+ end
187
+ unless ev == 1
188
+ ui.info('')
189
+ ui.info(env)
190
+ end
191
+ ui.info("-- #{ckbk} #{charthash[env][ckbk]['vs']}")
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ 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.1
4
+ version: 2.7.2
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-09-09 00:00:00.000000000 Z
12
+ date: 2014-09-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: chazzly@gmail.com
@@ -39,10 +39,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  version: '0'
40
40
  requirements: []
41
41
  rubyforge_project:
42
- rubygems_version: 1.8.28
42
+ rubygems_version: 1.8.24
43
43
  signing_key:
44
44
  specification_version: 3
45
45
  summary: Plug-in for Chef::Knife to print a chart of all cookbooks and the version
46
46
  constraints contained in each environment. See README.md for more details
47
47
  test_files: []
48
- has_rdoc: