knife-verschart 2.6
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/Verschart.rb +197 -0
- metadata +83 -0
data/lib/Verschart.rb
ADDED
@@ -0,0 +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
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-verschart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '2.6'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chaz Ruhl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! "knife-verschart\n===============\n\nPlug-in for Chef's knife to print
|
15
|
+
a chart of all cookbooks and the version constraints contained in each environment.\nAny
|
16
|
+
obsolete version constraints (i.e. constraints for cookbooks which do not exist
|
17
|
+
on the server) are also listed.\n\n\nInstallation and Config\n============\nPlace
|
18
|
+
the Verschart.rb file in your knife plugins directory. \n\nex. `cp Verschart.rb
|
19
|
+
~/.chef/plugins/knife/Verschart.rb`\n\nOne or more 'primary' environments can be
|
20
|
+
set either on the command line or in knife.rb. These environments will show in red
|
21
|
+
for any versions which are NOT frozen. \n\nThe list of environments is pulled from
|
22
|
+
the Chef server (_default is ignored). A prefered display order can be specified
|
23
|
+
either on the command line or in knife.rb.\n\n\nUSE\n===\n\nCommand line:\n-------------\n\n```sh\nknife
|
24
|
+
verschart [-e environment[,environment,...]]\n -e environment[,environment,...]
|
25
|
+
A comma-separated list of environments to be considered primary. Versions which
|
26
|
+
are NOT frozen willl be highlighted red.\n -o, --env_order env[,env,....] A
|
27
|
+
comma-separated list of environments to establish an display order. Any existing
|
28
|
+
environments not included in this list will be added at the end\n```\n\nknife.rb:\n---------\n```sh\nknife[:primary]
|
29
|
+
= \"PRODUCTION\" - Sets the primary environment(s)\nknife[:envorder] = \"Sandbox,Dev,Dev2,IT,Staging,PRODUCTION\"
|
30
|
+
- Sets the environment display order.\n```\n\nOutput will look something like this:\n\n```sh\nShowing
|
31
|
+
Versions for chef01.example.com\n\nVersion numbers in the Latest column in teal
|
32
|
+
are frozen\nVersion numbers in the PRODUCTION Environment(s) which are NOT frozen
|
33
|
+
will be red.\nVersion numbers which are different from the Latest, will be in blue\nRequested
|
34
|
+
Environment order is [\"Sandbox\", \"Dev\", \"Dev2\", \"IT\", \"Staging\", \"PRODUCTION\"]\n\n\nCookbooks
|
35
|
+
\ Latest Sandbox Dev IT Staging PRODUCTION\ncron
|
36
|
+
\ 1.2.8 <= 1.2.8 <= 1.2.8 <= 1.2.8 <= 1.2.8
|
37
|
+
\ <= 1.2.8 \nhostsfile 2.4.4 <= 2.4.4 <= 2.4.4 <=
|
38
|
+
2.4.4 <= 2.4.4 <= 2.4.4\nline 0.5.1 <= 0.5.1
|
39
|
+
\ <= 0.5.1 <= 0.5.1 <= 0.5.1 <= 0.5.1 \nlog_rotations 0.0.1
|
40
|
+
\ <= 0.0.1 <= 0.0.1 X \t X\t X\nlogrotate 1.4.0
|
41
|
+
\ <= 1.4.0 <= 1.4.0 <= 1.4.0 <= 1.4.0 <= 1.4.0 \nnetgroup 0.1.0
|
42
|
+
\ <= 0.1.0 <= 0.1.0 <= 0.1.0 <= 0.1.0 <= 0.1.0 \nohai 1.1.12
|
43
|
+
\ <= 1.1.12 <= 1.1.12 <= 1.1.12 <= 1.1.12 <= 1.1.12 \nssh 0.6.5
|
44
|
+
\ <= 0.6.5 <= 0.6.5 <= 0.6.5 <= 0.6.5 <= 0.6.5 \nssh-keys 1.0.0
|
45
|
+
\ <= 1.0.0 <= 1.0.0 <= 1.0.0 <= 1.0.0 <= 1.0.0 \nyum 3.1.4
|
46
|
+
\ <= 3.1.4 <= 3.1.4 <= 3.1.4 <= 3.1.4 <= 3.1.4 \n\nObsolete Version constraints
|
47
|
+
are listed below\n\nSandbox\n-- apache <= 3.2.1\n```\n\nTO-DO\n=====\n1. Denote
|
48
|
+
(perhaps with color) that a particular verison does not exist.\n2. Denote (perhaps
|
49
|
+
with color) constraints where no cookbook version exists to match the constraint.\n"
|
50
|
+
email: chazzly@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- lib/Verschart.rb
|
56
|
+
homepage: https://github.com/chazzly/knife-verschart
|
57
|
+
licenses:
|
58
|
+
- Apache
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.28
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Plug-in for Chef's knife to print a chart of all cookbooks and the version
|
81
|
+
constraints contained in each environment.
|
82
|
+
test_files: []
|
83
|
+
has_rdoc:
|