knife-env-diff 0.0.1

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 env-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 = 'knife-env-diff'
7
+ s.version = Knife::EnvDiff::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"]
12
+ s.email = ["jgoulah@gmail.com"]
13
+ s.homepage = "https://github.com/jgoulah/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,86 @@
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 EnvDiff < Chef::Knife
21
+
22
+ banner "knife env-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
+ env = load_environment(firstenv)
36
+ from_env[firstenv] = env.cookbook_versions
37
+
38
+ to_env = {}
39
+ otherenvs.each do |env_name|
40
+ env = load_environment(env_name)
41
+ to_env[env_name] = env.cookbook_versions
42
+ end
43
+
44
+ ui.msg "diffing environment " + firstenv + " against " + otherenvs.join(', ') + "\n\n"
45
+
46
+ from_env.each_value do |from_cookbooks|
47
+ from_cookbooks.each do |from_cookbook, from_version|
48
+
49
+ diff_versions = {}
50
+
51
+ to_env.each do |to_env, to_cookbooks|
52
+ to_version = to_cookbooks[from_cookbook] || "missing"
53
+ if from_version != to_version
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
61
+ diff_versions.each do |env, version|
62
+ ui.msg " #{env} version: "+ version
63
+ end
64
+ ui.msg "\n"
65
+ end
66
+
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ def load_environment(env)
73
+ e = Chef::Environment.load(env)
74
+ return e
75
+ rescue Net::HTTPServerException => e
76
+ if e.response.code.to_s == "404"
77
+ ui.error "The environment #{env} does not exist on the server, aborting."
78
+ Chef::Log.debug(e)
79
+ exit 1
80
+ else
81
+ raise
82
+ end
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,5 @@
1
+ module Knife
2
+ module EnvDiff
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-env-diff
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - John Goulah
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-02 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: 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.
22
+ email:
23
+ - jgoulah@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - knife-env-diff.gemspec
33
+ - lib/chef/knife/env-diff.rb
34
+ - lib/knife-env-diff/version.rb
35
+ has_rdoc: true
36
+ homepage: https://github.com/jgoulah/knife-env-diff
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ 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.
67
+ test_files: []
68
+