35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/chef/knife/sharp-environment-align.rb', line 35
def check_environments
not_up_to_date = Array.new
to_update = Array.new
unless File.exists?(environment_path)
ui.warn("Bad environment path, skipping environment sync.")
return to_update
end
ui.msg(ui.color("== Environments ==", :bold))
local_envs = Dir.glob(File.join(environment_path, "*.json")).map {|file| File.basename(file, ".json")}
remote_envs = Chef::Environment.list.keys
if local_envs.empty?
ui.warn("No local environment found, is the environment path correct ? (#{environment_path})")
return to_update
end
(local_envs - remote_envs).each do |env|
local_env = Chef::Environment.load_from_file(env)
message = "* #{local_env.name} environment is local only"
if ignore_list(:environments).include?(local_env.name)
message += " (ignored)"
else
not_up_to_date << local_env
end
ui.msg(message)
end
(remote_envs & local_envs).each do |env|
remote_env = Chef::Environment.load(env)
local_env = Chef::Environment.load_from_file(env)
diffs = relevant_env_keys.map do |method, display|
if remote_env.send(method) != local_env.send(method)
remote_env.send("#{method}=", local_env.send(method))
display
end
end.compact
unless diffs.empty?
message = "* #{remote_env.name} environment is not up-to-date (#{diffs.join(", ")})"
if ignore_list(:environments).include?(remote_env.name)
message += " (ignored)"
else
not_up_to_date << remote_env
end
ui.msg(message)
end
end
if !not_up_to_date.empty?
all = false
not_up_to_date.each do |env|
answer = all ? "Y" : ui.ask_question("> Update #{env.name} environment on server ? Y/N/(A)ll/(Q)uit ", :default => "N").upcase
if answer == "A"
all = true
elsif answer == "Q"
ui.msg "* Aborting environment alignment."
break
end
if all or answer == "Y"
to_update << env
else
ui.msg "* Skipping #{env.name} environment"
end
end
else
ui.msg "* Environments are up-to-date."
end
to_update
end
|