knife-pantry 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +53 -0
- data/Rakefile +2 -0
- data/knife-pantry.gemspec +27 -0
- data/lib/chef/knife/lookup.rb +53 -0
- data/lib/chef/knife/set.rb +58 -0
- data/lib/knife-pantry/version.rb +5 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a95cf4479bfbc01387b2e34e1d7045d893bde6d
|
4
|
+
data.tar.gz: 1e1a6e1bf995f6a2a67314e878b51c303fcd3622
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7feb6757b1c978bc2ec588e0f35e9a60ae0c75f9ba33a80a2fe60dda371e4a2a312a17da85c76d88bb2ab2ccbbd77a1e8918af5b3d3630abc45aa1e8bd1e98d
|
7
|
+
data.tar.gz: 28e35551e4031911962a593e8f3846d35bd59ae4f2eab926f0bbce9647e37184230bcaafa3dd33657d0d57a6d1da153f747e660c9300a37f10fa5cb688152a85
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2014 lsnyder
|
2
|
+
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Knife::Pantry
|
2
|
+
|
3
|
+
Knife plugin that allows you to manage environment specific cookbook versioning.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'knife-pantry'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install knife-pantry
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Currently there are two available commands:
|
22
|
+
#### lookup
|
23
|
+
Lookup allows you to see what version of the specified cookbook is being used in a particular environment.
|
24
|
+
The output also shows you the last five releases on your chef server.
|
25
|
+
```
|
26
|
+
knife pantry lookup <cookbook-name> <chef-environment>
|
27
|
+
[Environment found!] Looking for cookbook...
|
28
|
+
[Cookbook found!] Checking current version...
|
29
|
+
[Version found!] Finding latest releases...
|
30
|
+
[Releases found!]
|
31
|
+
0.2.6 <== Current version
|
32
|
+
0.2.5
|
33
|
+
0.2.4
|
34
|
+
0.2.3
|
35
|
+
0.2.2
|
36
|
+
```
|
37
|
+
|
38
|
+
#### set
|
39
|
+
Set allows you to, well... set a version for the specified cookbook in a particular environment, or environments.
|
40
|
+
A comma seperated list of environments can be passed in to set a version across multiple at once.
|
41
|
+
```
|
42
|
+
knife pantry set <cookbook-name> <version> <environments>
|
43
|
+
[Action Complete!] development => 0.2.5 => esfeeder
|
44
|
+
[Action Complete!] uat => 0.2.5 => esfeeder
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it ( https://github.com/[my-github-username]/knife-pantry/fork )
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'knife-pantry/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "knife-pantry"
|
8
|
+
spec.version = Knife::Pantry::VERSION
|
9
|
+
spec.authors = ["lsnyder\n"]
|
10
|
+
spec.email = ["luke.snyder@caa.com"]
|
11
|
+
spec.summary = %q{Knife pantry is a tool for managing environment controlled cookbook versioning. }
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "http://github.com/caagency/knife-pantry"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'chef', '~> 11.16', '>= 11.16.4'
|
22
|
+
spec.add_dependency 'json', '~> 1.8', '>= 1.8.1'
|
23
|
+
spec.add_dependency 'ffi-yajl', '1.2.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", '~> 1.6', '>= 1.6.2'
|
26
|
+
spec.add_development_dependency "rake", '~> 10.4', '>= 10.4.2'
|
27
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
|
5
|
+
class PantryLookup < Chef::Knife
|
6
|
+
|
7
|
+
banner "knife pantry lookup COOKBOOK ENVIRONMENT (options)"
|
8
|
+
|
9
|
+
def run
|
10
|
+
cbk = name_args.first
|
11
|
+
env = name_args.last
|
12
|
+
|
13
|
+
get_env(env)
|
14
|
+
version = get_cbk_versions(env, cbk)
|
15
|
+
get_past_versions(cbk, version)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_env(env)
|
19
|
+
environments = []
|
20
|
+
for key in rest.get_rest('environments')
|
21
|
+
environments.push(key[0])
|
22
|
+
end
|
23
|
+
if !(environments.include?(env))
|
24
|
+
puts "Specified environment does not exist"
|
25
|
+
else
|
26
|
+
puts "[Environment found!] Looking for cookbook..."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_cbk_versions(env, cbk)
|
31
|
+
cookbooks = rest.get_rest("environments/#{env}/cookbooks")
|
32
|
+
if !(cookbooks.has_key?(cbk))
|
33
|
+
puts "#{cbk} not found in #{env}"
|
34
|
+
else
|
35
|
+
puts "[Cookbook found!] Checking current version..."
|
36
|
+
version = cookbooks[cbk]['versions'][0]['version']
|
37
|
+
puts "[Version found!] Finding latest releases..."
|
38
|
+
end
|
39
|
+
return version
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_past_versions(cbk, version)
|
43
|
+
available_versions= rest.get_rest("cookbooks/#{cbk}")
|
44
|
+
puts "[Releases found!]"
|
45
|
+
available_versions[cbk]['versions'][0..4].each { |release|
|
46
|
+
if release['version'] == version
|
47
|
+
puts release['version'] + " <== Current version"
|
48
|
+
else
|
49
|
+
puts release['version']
|
50
|
+
end
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
|
5
|
+
class PantrySet < Chef::Knife
|
6
|
+
|
7
|
+
banner "knife pantry set COOKBOOK VERSION [ENVIRONMENT] (options)"
|
8
|
+
|
9
|
+
def run
|
10
|
+
options = {
|
11
|
+
cbk: name_args.first,
|
12
|
+
ver: name_args[1],
|
13
|
+
env: name_args.last
|
14
|
+
}
|
15
|
+
|
16
|
+
if options[:ver] == 'latest'
|
17
|
+
available_versions = rest.get_rest("cookbooks/#{options[:cbk]}")
|
18
|
+
options[:ver] = available_versions[options[:cbk]]['versions'][0]['version']
|
19
|
+
end
|
20
|
+
|
21
|
+
options[:env] = options[:env].split(',')
|
22
|
+
options[:env].each {|x|
|
23
|
+
options[:current_env] = x
|
24
|
+
if set(get_cbk_list(options))
|
25
|
+
puts "[Action Complete!] #{options[:current_env]} => #{options[:ver]} => #{options[:cbk]}"
|
26
|
+
else
|
27
|
+
puts "[No Action!] #{options[:current_env]} already using #{options[:cbk]} #{options[:ver]}"
|
28
|
+
end
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_cbk_list(options)
|
33
|
+
chef_env = rest.get_rest("environments/#{options[:current_env]}")
|
34
|
+
env_json = JSON.parse(chef_env.to_json(chef_env))
|
35
|
+
cbk_list = env_json['cookbook_versions']
|
36
|
+
|
37
|
+
if cbk_list.has_key?(options[:cbk])
|
38
|
+
if cbk_list[options[:cbk]] == "= " + options[:ver]
|
39
|
+
return nil
|
40
|
+
else
|
41
|
+
cbk_list[options[:cbk]] = "= " + options[:ver]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
new_cbk_list = cbk_list
|
46
|
+
env_json['cookbook_versions'] = new_cbk_list
|
47
|
+
return env_json
|
48
|
+
end
|
49
|
+
|
50
|
+
def set(env_json)
|
51
|
+
if env_json != nil
|
52
|
+
rest.put_rest("environments/" + env_json['name'], env_json)
|
53
|
+
return true
|
54
|
+
else
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-pantry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- |
|
8
|
+
lsnyder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '11.16'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 11.16.4
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - "~>"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '11.16'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 11.16.4
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: json
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.8.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.8'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.8.1
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: ffi-yajl
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.2.0
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.2.0
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: bundler
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.6'
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.6.2
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '1.6'
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.6.2
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
name: rake
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '10.4'
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 10.4.2
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '10.4'
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 10.4.2
|
108
|
+
description: Knife pantry is a tool for managing environment controlled cookbook versioning.
|
109
|
+
email:
|
110
|
+
- luke.snyder@caa.com
|
111
|
+
executables: []
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- ".gitignore"
|
116
|
+
- Gemfile
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- knife-pantry.gemspec
|
121
|
+
- lib/chef/knife/lookup.rb
|
122
|
+
- lib/chef/knife/set.rb
|
123
|
+
- lib/knife-pantry/version.rb
|
124
|
+
homepage: http://github.com/caagency/knife-pantry
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.2.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Knife pantry is a tool for managing environment controlled cookbook versioning.
|
148
|
+
test_files: []
|