jvoorhis-knife-env-diff 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ # knife-env-diff
2
+
3
+ A plugin for Chef::Knife which will diff the cookbook versions of two or more environments.
4
+
5
+ ## Usage
6
+
7
+ Supply two or more environments to get a diff of their cookbook versions
8
+
9
+ ```
10
+ % knife environment diff development production
11
+
12
+ diffing environment development against production
13
+
14
+ cookbook: hadoop
15
+ development version: = 0.1.0
16
+ production version: = 0.1.8
17
+
18
+ cookbook: mysql
19
+ development version: = 0.2.4
20
+ production version: = 0.2.5
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ #### Script install
26
+
27
+ Copy the knife-env-diff script from lib/chef/knife/env-diff.rb to your ~/.chef/plugins/knife directory.
28
+
29
+ #### Gem install
30
+
31
+ knife-env-diff is available on rubygems.org - if you have that source in your gemrc, you can simply use:
32
+
33
+ gem install knife-env-diff
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "knife-env-diff/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'jvoorhis-knife-env-diff'
7
+ s.version = Knife::EnvironmentDiff::VERSION
8
+ s.date = '2012-01-02'
9
+ s.summary = "A plugin for Chef::Knife which displays the roles that are included recursively within a role and optionally displays all the roles that include it."
10
+ s.description = s.summary
11
+ s.authors = ["John Goulah", "Jeremy Voorhis"]
12
+ s.email = ["jvoorhis@gmail.com"]
13
+ s.homepage = "https://github.com/jvoorhis/knife-env-diff"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,82 @@
1
+ #
2
+ # Author:: John Goulah (<jgoulah@gmail.com>)
3
+ # Copyright:: Copyright (c) 2011 John Goulah
4
+ #
5
+ ## Licensed under the Apache License, Version 2.0 (the "License");
6
+ ## you may not use this file except in compliance with the License.
7
+ ## You may obtain a copy of the License at
8
+ ##
9
+ ## http://www.apache.org/licenses/LICENSE-2.0
10
+ ##
11
+ ## Unless required by applicable law or agreed to in writing, software
12
+ ## distributed under the License is distributed on an "AS IS" BASIS,
13
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ## See the License for the specific language governing permissions and
15
+ ## limitations under the License.
16
+ ##
17
+ #
18
+
19
+ module GoulahKnifePlugins
20
+ class EnvironmentDiff < Chef::Knife
21
+
22
+ banner "knife environment diff [ENVIRONMENTS...]"
23
+
24
+ def run
25
+ if name_args.size < 2
26
+ ui.error("You need to supply at least two environments")
27
+ show_usage
28
+ exit 1
29
+ end
30
+
31
+ firstenv = name_args.first
32
+ otherenvs = name_args.slice(1, name_args.length - 1)
33
+
34
+ from_env = {}
35
+ from_env[firstenv] = get_env_cookbooks(firstenv)
36
+
37
+ to_env = {}
38
+ otherenvs.each do |env_name|
39
+ to_env[env_name] = get_env_cookbooks(env_name)
40
+ end
41
+
42
+ ui.msg "diffing environment " + firstenv + " against " + otherenvs.join(', ') + "\n\n"
43
+
44
+ from_env.each_value do |from_cookbooks|
45
+ from_cookbooks.each do |from_cookbook, from_data|
46
+ diff_versions = {}
47
+
48
+ from_version = get_cookbook_version(from_data)
49
+
50
+ to_env.each do |to_env, to_cookbooks|
51
+ to_version = get_cookbook_version(to_cookbooks[from_cookbook])
52
+
53
+ if from_version != to_version || from_version.nil?
54
+ diff_versions[to_env] = to_version
55
+ end
56
+ end
57
+
58
+ unless diff_versions.empty?
59
+ ui.msg "cookbook: "+ from_cookbook
60
+ ui.msg " #{firstenv} version: "+ (from_version || 'none')
61
+ diff_versions.each do |env, version|
62
+ ui.msg " #{env} version: "+ version
63
+ end
64
+ ui.msg "\n"
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def get_env_cookbooks(env)
71
+ rest.get_rest("environments/#{env}/cookbooks")
72
+ end
73
+
74
+ def get_cookbook_version(data)
75
+ if data['versions'].empty?
76
+ 'none'
77
+ else
78
+ data['versions'].first['version']
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ module Knife
2
+ module EnvironmentDiff
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jvoorhis-knife-env-diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Goulah
9
+ - Jeremy Voorhis
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-02 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: A plugin for Chef::Knife which displays the roles that are included recursively
16
+ within a role and optionally displays all the roles that include it.
17
+ email:
18
+ - jvoorhis@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - README.md
24
+ - knife-env-diff.gemspec
25
+ - lib/chef/knife/env-diff.rb
26
+ - lib/knife-env-diff/version.rb
27
+ homepage: https://github.com/jvoorhis/knife-env-diff
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.11
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: A plugin for Chef::Knife which displays the roles that are included recursively
51
+ within a role and optionally displays all the roles that include it.
52
+ test_files: []
53
+ has_rdoc: