Skip to content

Commit

Permalink
can now diff against unconstrained cookbooks, will use latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
John Goulah committed Mar 10, 2012
1 parent 3c006c0 commit 8320e99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
25 changes: 8 additions & 17 deletions lib/chef/knife/env-diff.rb
Expand Up @@ -32,24 +32,24 @@ def run
otherenvs = name_args.slice(1, name_args.length - 1) otherenvs = name_args.slice(1, name_args.length - 1)


from_env = {} from_env = {}
env = load_environment(firstenv) from_env[firstenv] = get_env_cookbooks(firstenv)
from_env[firstenv] = env.cookbook_versions


to_env = {} to_env = {}
otherenvs.each do |env_name| otherenvs.each do |env_name|
env = load_environment(env_name) to_env[env_name] = get_env_cookbooks(env_name)
to_env[env_name] = env.cookbook_versions
end end


ui.msg "diffing environment " + firstenv + " against " + otherenvs.join(', ') + "\n\n" ui.msg "diffing environment " + firstenv + " against " + otherenvs.join(', ') + "\n\n"


from_env.each_value do |from_cookbooks| from_env.each_value do |from_cookbooks|
from_cookbooks.each do |from_cookbook, from_version| from_cookbooks.each do |from_cookbook, from_data|
from_version = from_data["versions"].first['version']


diff_versions = {} diff_versions = {}


to_env.each do |to_env, to_cookbooks| to_env.each do |to_env, to_cookbooks|
to_version = to_cookbooks[from_cookbook] || "missing" to_version = to_cookbooks[from_cookbook]["versions"].first['version']

if from_version != to_version if from_version != to_version
diff_versions[to_env] = to_version diff_versions[to_env] = to_version
end end
Expand All @@ -69,17 +69,8 @@ def run


end end


def load_environment(env) def get_env_cookbooks(env)
e = Chef::Environment.load(env) rest.get_rest("environments/#{env}/cookbooks")
return e
rescue Net::HTTPServerException => e
if e.response.code.to_s == "404"
ui.error "The environment #{env} does not exist on the server, aborting."
Chef::Log.debug(e)
exit 1
else
raise
end
end end


end end
Expand Down
2 changes: 1 addition & 1 deletion lib/knife-env-diff/version.rb
@@ -1,5 +1,5 @@
module Knife module Knife
module EnvironmentDiff module EnvironmentDiff
VERSION = "0.0.2" VERSION = "0.0.3"
end end
end end

0 comments on commit 8320e99

Please sign in to comment.