knife-cookbook-cleanup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e259c1fa667c48444ac340b4c939c64838c0c981
4
+ data.tar.gz: 5e4b33cf51308b6a18b214fa0ae01765d90ca845
5
+ SHA512:
6
+ metadata.gz: a90b939bf2c8932330db75b36b1928e2ebe6a1007fd8f26f81c5fefec610dd1a72edb85771a9bcd061a09504e8039b2ef9cfae13d37fc5dc41dfa8eb1bc98a01
7
+ data.tar.gz: bf8b62b15495ff73322dd5325db209a92a0fe22e6f8c293bbdb480adceefcf0baf9d06c1e3d49aeefad27489e583c910466c0fd7aaf2c9aea6cc616c58db79a0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-cookbook-cleanup.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ knife-cookbook-cleanup (0.1.0)
5
+ chef (> 0.10.10)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ chef (11.10.4)
11
+ chef-zero (~> 1.7, >= 1.7.2)
12
+ diff-lcs (~> 1.2, >= 1.2.4)
13
+ erubis (~> 2.7)
14
+ highline (~> 1.6, >= 1.6.9)
15
+ json (>= 1.4.4, <= 1.8.1)
16
+ mime-types (~> 1.16)
17
+ mixlib-authentication (~> 1.3)
18
+ mixlib-cli (~> 1.4)
19
+ mixlib-config (~> 2.0)
20
+ mixlib-log (~> 1.3)
21
+ mixlib-shellout (~> 1.3)
22
+ net-ssh (~> 2.6)
23
+ net-ssh-multi (~> 1.1)
24
+ ohai (~> 6.0)
25
+ pry (~> 0.9)
26
+ puma (~> 1.6)
27
+ rest-client (>= 1.0.4, < 1.7.0)
28
+ yajl-ruby (~> 1.1)
29
+ chef-zero (1.7.3)
30
+ hashie (~> 2.0)
31
+ json
32
+ mixlib-log (~> 1.3)
33
+ moneta (< 0.7.0)
34
+ rack
35
+ coderay (1.1.0)
36
+ diff-lcs (1.2.5)
37
+ erubis (2.7.0)
38
+ hashie (2.0.5)
39
+ highline (1.6.21)
40
+ ipaddress (0.8.0)
41
+ json (1.8.1)
42
+ method_source (0.8.2)
43
+ mime-types (1.25.1)
44
+ mixlib-authentication (1.3.0)
45
+ mixlib-log
46
+ mixlib-cli (1.4.0)
47
+ mixlib-config (2.1.0)
48
+ mixlib-log (1.6.0)
49
+ mixlib-shellout (1.3.0)
50
+ moneta (0.6.0)
51
+ net-ssh (2.8.0)
52
+ net-ssh-gateway (1.2.0)
53
+ net-ssh (>= 2.6.5)
54
+ net-ssh-multi (1.2.0)
55
+ net-ssh (>= 2.6.5)
56
+ net-ssh-gateway (>= 1.2.0)
57
+ ohai (6.20.0)
58
+ ipaddress
59
+ mixlib-cli
60
+ mixlib-config
61
+ mixlib-log
62
+ mixlib-shellout
63
+ systemu (~> 2.5.2)
64
+ yajl-ruby
65
+ pry (0.9.12.6)
66
+ coderay (~> 1.0)
67
+ method_source (~> 0.8)
68
+ slop (~> 3.4)
69
+ puma (1.6.3)
70
+ rack (~> 1.2)
71
+ rack (1.5.2)
72
+ rake (10.2.2)
73
+ rest-client (1.6.7)
74
+ mime-types (>= 1.16)
75
+ slop (3.5.0)
76
+ systemu (2.5.2)
77
+ yajl-ruby (1.2.0)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ bundler (~> 1.6)
84
+ knife-cookbook-cleanup!
85
+ rake
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Anthony Goddard <anthony@anthonygoddard.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ knife-cookbook-cleanup
2
+ ========
3
+ A knife plugin for removing old versions of cookbooks from your chef-server, the plugin will only leave the latest versions of cookbooks on the server.
4
+
5
+
6
+ Installing knife-cookbook-cleanup
7
+ -------------------
8
+
9
+ #### Gem install
10
+
11
+ add `knife-cookbook-cleanup` to your Gemfile, or simply
12
+
13
+ gem install knife-cookbook-cleanup
14
+
15
+ Usage
16
+ ---------------
17
+
18
+ knife cookbook cleanup
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,27 @@
1
+
2
+ # -*- encoding: utf-8 -*-
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "knife-cookbook-cleanup/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "knife-cookbook-cleanup"
8
+ s.version = Knife::CookbookCleanup::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.has_rdoc = true
11
+ s.extra_rdoc_files = ["README.md", "LICENSE" ]
12
+ s.authors = ["Anthony Goddard","Fletcher Nichol","Heavy Water Operations"]
13
+ s.email = ["support@hw-ops.com"]
14
+ s.homepage = "https://github.com/heavywater/knife-cookbook-cleanup"
15
+ s.summary = %q{Chef Knife plugin to remove all cookbooks except the latest}
16
+ s.description = %q{Deletes all cookbooks from the chef server except for the latest versions}
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'chef', '> 0.10.10'
24
+
25
+ s.add_development_dependency 'bundler', '~> 1.6'
26
+ s.add_development_dependency 'rake'
27
+ end
@@ -0,0 +1,72 @@
1
+ #
2
+ # Author:: Heavy Water Operations (<support@hw-ops.com>)
3
+ # Copyright:: Copyright (c) 2014 Heavy Water Operations, LLC.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CookbookCleanup < Knife
24
+
25
+ deps do
26
+ require 'chef/knife/bootstrap'
27
+ Chef::Knife::Bootstrap.load_deps
28
+ end
29
+
30
+ banner "knife cookbook cleanup"
31
+
32
+ def run
33
+ all_cookbooks = rest.get_rest('/cookbooks?num_versions=all')
34
+ drop_cookbooks = Hash.new
35
+ keep_cookbooks = Hash.new
36
+ all_cookbooks.each do |cb|
37
+ cookbook_name = cb[0]
38
+ sorted_versions = cb[1]["versions"].map{ |v| v["version"] }.sort{ |x, y|Gem::Version.new(x) <=> Gem::Version.new(y) }
39
+ keep_versions = sorted_versions.pop
40
+ dropped_versions = sorted_versions
41
+ drop_cookbooks[cookbook_name] = dropped_versions
42
+ keep_cookbooks[cookbook_name] = keep_versions
43
+ end
44
+ keep_cookbooks.delete_if { |k, v|v.empty? }
45
+ drop_cookbooks.delete_if { |k, v|v.empty? }
46
+
47
+ if drop_cookbooks.empty?
48
+ ui.info "No old cookbook versions were found"
49
+ exit 0
50
+ end
51
+
52
+ ui.msg ""
53
+ ui.msg "The following cookbook versions will remain on the chef server:"
54
+ ui.msg ""
55
+ ui.msg ui.output(keep_cookbooks)
56
+ ui.msg ""
57
+ ui.msg "The following cookbook versions will be deleted:"
58
+ ui.msg ""
59
+ ui.msg ui.output(drop_cookbooks)
60
+ ui.msg ""
61
+ ui.confirm("Do you really want to delete these cookbooks? (Y/N) ", false)
62
+
63
+ drop_cookbooks.each do |cookbook, versions|
64
+ versions.each do |version|
65
+ rest.delete_rest("cookbooks/#{cookbook}/#{version}")
66
+ ui.info("Deleted cookbook #{cookbook.ljust(25)} [#{version}]")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,6 @@
1
+ module Knife
2
+ module CookbookCleanup
3
+ VERSION = "0.1.0"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-cookbook-cleanup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Goddard
8
+ - Fletcher Nichol
9
+ - Heavy Water Operations
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-04-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: chef
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">"
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">"
27
+ - !ruby/object:Gem::Version
28
+ version: 0.10.10
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.6'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.6'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ description: Deletes all cookbooks from the chef server except for the latest versions
58
+ email:
59
+ - support@hw-ops.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - README.md
64
+ - LICENSE
65
+ files:
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - knife-cookbook-cleanup.gemspec
72
+ - lib/chef/knife/cookbook_cleanup.rb
73
+ - lib/knife-cookbook-cleanup/version.rb
74
+ homepage: https://github.com/heavywater/knife-cookbook-cleanup
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.0
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Chef Knife plugin to remove all cookbooks except the latest
97
+ test_files: []