knife-spork 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +35 -35
  3. data/lib/chef/knife/spork-bump.rb +100 -100
  4. data/lib/chef/knife/spork-check.rb +165 -161
  5. data/lib/chef/knife/spork-databag-create.rb +54 -54
  6. data/lib/chef/knife/spork-databag-delete.rb +51 -51
  7. data/lib/chef/knife/spork-databag-edit.rb +54 -54
  8. data/lib/chef/knife/spork-databag-fromfile.rb +88 -88
  9. data/lib/chef/knife/spork-delete.rb +132 -132
  10. data/lib/chef/knife/spork-environment-check.rb +90 -90
  11. data/lib/chef/knife/spork-environment-create.rb +63 -63
  12. data/lib/chef/knife/spork-environment-delete.rb +38 -38
  13. data/lib/chef/knife/spork-environment-edit.rb +40 -40
  14. data/lib/chef/knife/spork-environment-fromfile.rb +46 -46
  15. data/lib/chef/knife/spork-info.rb +34 -34
  16. data/lib/chef/knife/spork-node-create.rb +41 -41
  17. data/lib/chef/knife/spork-node-delete.rb +41 -41
  18. data/lib/chef/knife/spork-node-edit.rb +48 -48
  19. data/lib/chef/knife/spork-node-fromfile.rb +46 -46
  20. data/lib/chef/knife/spork-node-runlistadd.rb +51 -51
  21. data/lib/chef/knife/spork-node-runlistremove.rb +44 -44
  22. data/lib/chef/knife/spork-node-runlistset.rb +44 -44
  23. data/lib/chef/knife/spork-omni.rb +112 -112
  24. data/lib/chef/knife/spork-promote.rb +197 -197
  25. data/lib/chef/knife/spork-role-create.rb +46 -46
  26. data/lib/chef/knife/spork-role-delete.rb +50 -50
  27. data/lib/chef/knife/spork-role-edit.rb +40 -40
  28. data/lib/chef/knife/spork-role-fromfile.rb +65 -65
  29. data/lib/chef/knife/spork-upload.rb +151 -151
  30. data/lib/chef/knife/spork-version.rb +12 -12
  31. data/lib/knife-spork.rb +3 -3
  32. data/lib/knife-spork/plugins.rb +27 -27
  33. data/lib/knife-spork/plugins/campfire.rb +219 -219
  34. data/lib/knife-spork/plugins/eventinator.rb +329 -329
  35. data/lib/knife-spork/plugins/foodcritic.rb +46 -46
  36. data/lib/knife-spork/plugins/git.rb +393 -399
  37. data/lib/knife-spork/plugins/graphite.rb +25 -25
  38. data/lib/knife-spork/plugins/grove.rb +167 -167
  39. data/lib/knife-spork/plugins/hipchat.rb +171 -171
  40. data/lib/knife-spork/plugins/influxdb.rb +28 -28
  41. data/lib/knife-spork/plugins/irccat.rb +332 -332
  42. data/lib/knife-spork/plugins/jabber.rb +133 -133
  43. data/lib/knife-spork/plugins/plugin.rb +117 -117
  44. data/lib/knife-spork/plugins/rubocop.rb +56 -56
  45. data/lib/knife-spork/plugins/slack.rb +125 -125
  46. data/lib/knife-spork/plugins/statusnet.rb +122 -122
  47. data/lib/knife-spork/runner.rb +342 -342
  48. data/lib/knife-spork/version.rb +5 -5
  49. metadata +4 -51
  50. data/.gitignore +0 -21
  51. data/.ruby-gemset +0 -1
  52. data/.ruby-version +0 -1
  53. data/.travis.yml +0 -3
  54. data/CHANGELOG.md +0 -445
  55. data/Gemfile +0 -3
  56. data/README.md +0 -544
  57. data/Rakefile +0 -35
  58. data/knife-spork.gemspec +0 -28
  59. data/plugins/Campfire.md +0 -43
  60. data/plugins/Eventinator.md +0 -30
  61. data/plugins/Foodcritic.md +0 -53
  62. data/plugins/Git.md +0 -53
  63. data/plugins/Graphite.md +0 -30
  64. data/plugins/Grove.md +0 -31
  65. data/plugins/HipChat.md +0 -69
  66. data/plugins/Influxdb.md +0 -25
  67. data/plugins/Irccat.md +0 -50
  68. data/plugins/Jabber.md +0 -61
  69. data/plugins/README.md +0 -70
  70. data/plugins/Rubocop.md +0 -110
  71. data/plugins/Slack.md +0 -48
  72. data/plugins/StatusNet.md +0 -41
  73. data/plugins/Template.md +0 -34
  74. data/spec/spec_helper.rb +0 -10
  75. data/spec/test_helpers.rb +0 -46
  76. data/spec/unit/fixtures/config/spork-config.yml +0 -1
  77. data/spec/unit/fixtures/cookbooks/example/metadata.rb +0 -8
  78. data/spec/unit/fixtures/environments/example.json +0 -12
  79. data/spec/unit/fixtures/knife.rb +0 -6
  80. data/spec/unit/fixtures/test_client.pem +0 -27
  81. data/spec/unit/spork_bump_spec.rb +0 -75
  82. data/spec/unit/spork_info_spec.rb +0 -40
  83. data/spec/unit/spork_promote_spec.rb +0 -77
  84. data/spec/unit/spork_upload_spec.rb +0 -46
@@ -1,112 +1,112 @@
1
- require 'chef/knife'
2
-
3
- module KnifeSpork
4
- class SporkOmni < Chef::Knife
5
-
6
- deps do
7
- require 'knife-spork/runner'
8
- begin
9
- require 'berkshelf'
10
- rescue LoadError; end
11
- end
12
-
13
- banner 'knife spork omni COOKBOOK (options)'
14
-
15
- option :cookbook_path,
16
- :short => '-o PATH:PATH',
17
- :long => '--cookbook-path PATH:PATH',
18
- :description => 'A colon-separated path to look for cookbooks in',
19
- :proc => lambda { |o| o.split(':') }
20
-
21
- option :depends,
22
- :short => '-D',
23
- :long => '--include-dependencies',
24
- :description => 'Also upload cookbook dependencies during the upload step'
25
-
26
- option :bump_level,
27
- :short => '-l',
28
- :long => '--bump-level [major|minor|patch]',
29
- :description => 'Version level to bump the cookbook (defaults to patch)',
30
- :default => nil
31
-
32
- option :omni_environment,
33
- :short => '-e',
34
- :long => '--environment ENVIRONMENT',
35
- :description => 'Environment to promote the cookbook to',
36
- :default => nil
37
-
38
- option :remote,
39
- :long => '--remote',
40
- :description => 'Make omni finish with promote --remote instead of a local promote',
41
- :default => nil
42
-
43
- option :berksfile,
44
- :short => '-b',
45
- :long => '--berksfile BERKSFILE',
46
- :description => 'Path to a Berksfile to operate from',
47
- :default => nil,
48
- :proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
49
-
50
- def run
51
- self.class.send(:include, KnifeSpork::Runner)
52
- self.config = Chef::Config.merge!(config)
53
-
54
- if name_args.empty?
55
- ui.fatal 'You must specify a cookbook name!'
56
- show_usage
57
- exit(1)
58
- end
59
-
60
- # Temporary fix for #138 to allow Berkshelf functionality
61
- # to be bypassed until #85 has been completed and Berkshelf 3 support added
62
- unload_berkshelf_if_specified
63
-
64
- cookbook = name_args.first
65
-
66
- run_plugins(:before_omni)
67
- omni(cookbook)
68
- run_plugins(:after_omni)
69
- end
70
-
71
- private
72
-
73
- def bump(cookbook)
74
- ui.msg "OMNI: Bumping #{cookbook}"
75
- bump = SporkBump.new
76
- bump.name_args = [cookbook,config[:bump_level]]
77
- bump.run
78
- end
79
-
80
- def upload(cookbook)
81
- ui.msg "OMNI: Uploading #{cookbook}"
82
- upload = SporkUpload.new
83
- upload.name_args = [cookbook]
84
- upload.config[:cookbook_path] = config[:cookbook_path]
85
- upload.config[:depends] = config[:depends]
86
- upload.run
87
- end
88
-
89
- def promote(cookbook)
90
- ui.msg "OMNI: Promoting #{cookbook}"
91
- promote = SporkPromote.new
92
- if config[:omni_environment]
93
- promote.name_args = [config[:omni_environment],cookbook]
94
- else
95
- promote.name_args = [cookbook]
96
- end
97
- promote.config[:remote] = config[:remote]
98
- if defined?(::Berkshelf)
99
- promote.config[:berksfile] = config[:berksfile]
100
- end
101
- promote.run
102
- end
103
-
104
- def omni(cookbook)
105
- bump(cookbook)
106
- ui.msg ""
107
- upload(cookbook)
108
- ui.msg ""
109
- promote(cookbook)
110
- end
111
- end
112
- end
1
+ require 'chef/knife'
2
+
3
+ module KnifeSpork
4
+ class SporkOmni < Chef::Knife
5
+
6
+ deps do
7
+ require 'knife-spork/runner'
8
+ begin
9
+ require 'berkshelf'
10
+ rescue LoadError; end
11
+ end
12
+
13
+ banner 'knife spork omni COOKBOOK (options)'
14
+
15
+ option :cookbook_path,
16
+ :short => '-o PATH:PATH',
17
+ :long => '--cookbook-path PATH:PATH',
18
+ :description => 'A colon-separated path to look for cookbooks in',
19
+ :proc => lambda { |o| o.split(':') }
20
+
21
+ option :depends,
22
+ :short => '-D',
23
+ :long => '--include-dependencies',
24
+ :description => 'Also upload cookbook dependencies during the upload step'
25
+
26
+ option :bump_level,
27
+ :short => '-l',
28
+ :long => '--bump-level [major|minor|patch]',
29
+ :description => 'Version level to bump the cookbook (defaults to patch)',
30
+ :default => nil
31
+
32
+ option :omni_environment,
33
+ :short => '-e',
34
+ :long => '--environment ENVIRONMENT',
35
+ :description => 'Environment to promote the cookbook to',
36
+ :default => nil
37
+
38
+ option :remote,
39
+ :long => '--remote',
40
+ :description => 'Make omni finish with promote --remote instead of a local promote',
41
+ :default => nil
42
+
43
+ option :berksfile,
44
+ :short => '-b',
45
+ :long => '--berksfile BERKSFILE',
46
+ :description => 'Path to a Berksfile to operate from',
47
+ :default => nil,
48
+ :proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
49
+
50
+ def run
51
+ self.class.send(:include, KnifeSpork::Runner)
52
+ self.config = Chef::Config.merge!(config)
53
+
54
+ if name_args.empty?
55
+ ui.fatal 'You must specify a cookbook name!'
56
+ show_usage
57
+ exit(1)
58
+ end
59
+
60
+ # Temporary fix for #138 to allow Berkshelf functionality
61
+ # to be bypassed until #85 has been completed and Berkshelf 3 support added
62
+ unload_berkshelf_if_specified
63
+
64
+ cookbook = name_args.first
65
+
66
+ run_plugins(:before_omni)
67
+ omni(cookbook)
68
+ run_plugins(:after_omni)
69
+ end
70
+
71
+ private
72
+
73
+ def bump(cookbook)
74
+ ui.msg "OMNI: Bumping #{cookbook}"
75
+ bump = SporkBump.new
76
+ bump.name_args = [cookbook,config[:bump_level]]
77
+ bump.run
78
+ end
79
+
80
+ def upload(cookbook)
81
+ ui.msg "OMNI: Uploading #{cookbook}"
82
+ upload = SporkUpload.new
83
+ upload.name_args = [cookbook]
84
+ upload.config[:cookbook_path] = config[:cookbook_path]
85
+ upload.config[:depends] = config[:depends]
86
+ upload.run
87
+ end
88
+
89
+ def promote(cookbook)
90
+ ui.msg "OMNI: Promoting #{cookbook}"
91
+ promote = SporkPromote.new
92
+ if config[:omni_environment]
93
+ promote.name_args = [config[:omni_environment],cookbook]
94
+ else
95
+ promote.name_args = [cookbook]
96
+ end
97
+ promote.config[:remote] = config[:remote]
98
+ if defined?(::Berkshelf)
99
+ promote.config[:berksfile] = config[:berksfile]
100
+ end
101
+ promote.run
102
+ end
103
+
104
+ def omni(cookbook)
105
+ bump(cookbook)
106
+ ui.msg ""
107
+ upload(cookbook)
108
+ ui.msg ""
109
+ promote(cookbook)
110
+ end
111
+ end
112
+ end
@@ -1,197 +1,197 @@
1
- require 'chef/knife'
2
-
3
- module KnifeSpork
4
- class SporkPromote < Chef::Knife
5
-
6
- deps do
7
- require 'chef/exceptions'
8
- require 'knife-spork/runner'
9
- begin
10
- require 'berkshelf'
11
- rescue LoadError; end
12
- end
13
-
14
- banner 'knife spork promote ENVIRONMENT COOKBOOK (options)'
15
-
16
- option :version,
17
- :short => '-v',
18
- :long => '--version VERSION',
19
- :description => 'Set the environment\'s version constraint to the specified version',
20
- :default => nil
21
-
22
- option :remote,
23
- :long => '--remote',
24
- :description => 'Save the environment to the chef server in addition to the local JSON file',
25
- :default => nil
26
-
27
- option :cookbook_path,
28
- :short => '-o PATH:PATH',
29
- :long => '--cookbook-path PATH:PATH',
30
- :description => 'A colon-separated path to look for cookbooks in',
31
- :proc => lambda { |o| o.split(':') }
32
-
33
- if defined?(::Berkshelf)
34
- option :berksfile,
35
- :short => '-b',
36
- :long => '--berksfile BERKSFILE',
37
- :description => 'Path to a Berksfile to operate off of',
38
- :default => File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME)
39
- end
40
-
41
- def run
42
- self.class.send(:include, KnifeSpork::Runner)
43
- self.config = Chef::Config.merge!(config)
44
-
45
- if @name_args.empty?
46
- show_usage
47
- ui.error("You must specify the cookbook and environment to promote to")
48
- exit 1
49
- end
50
-
51
- # Temporary fix for #138 to allow Berkshelf functionality
52
- # to be bypassed until #85 has been completed and Berkshelf 3 support added
53
- unload_berkshelf_if_specified
54
-
55
- #First load so plugins etc know what to work with
56
- @environments, @cookbook = load_environments_and_cookbook
57
-
58
- run_plugins(:before_promote)
59
-
60
- #Reload cookbook and env in case a VCS plugin found updates
61
- @environments, @cookbook = load_environments_and_cookbook
62
-
63
- check_cookbook_uploaded(@cookbook)
64
- check_cookbook_latest(@cookbook)
65
-
66
- @environments.each do |e|
67
- environment = load_environment_from_file(e)
68
-
69
-
70
- promote(environment, @cookbook)
71
-
72
- ui.msg "Saving changes to #{e}.json"
73
-
74
- new_environment_json = pretty_print_json(environment.to_hash)
75
- save_environment_changes(e, new_environment_json)
76
-
77
- if config[:remote] || spork_config.always_promote_remote
78
- ui.msg "Uploading #{environment.name}.json to Chef Server"
79
- save_environment_changes_remote(e)
80
- ui.info "Promotion complete at #{Time.now}!"
81
- else
82
- ui.info "Promotion complete. Don't forget to upload your changed #{environment.name}.json to Chef Server"
83
- end
84
- end
85
- run_plugins(:after_promote_local)
86
- if config[:remote] || spork_config.always_promote_remote
87
- run_plugins(:after_promote_remote)
88
- end
89
- end
90
-
91
- def update_version_constraints(environment, cookbook, new_version)
92
- validate_version!(new_version)
93
- if spork_config.preserve_constraint_operators
94
-
95
- cb_version = environment.cookbook_versions[cookbook]
96
- if cb_version
97
- if cb_version.length > 0
98
- constraint_operator = cb_version.split.first
99
- else
100
- constraint_operator = "="
101
- end
102
- ui.msg "Preserving existing version constraint operator: #{constraint_operator}"
103
- else
104
- constraint_operator = "="
105
- end
106
- else
107
- constraint_operator = "="
108
- end
109
- environment.cookbook_versions[cookbook] = "#{constraint_operator} #{new_version}"
110
- end
111
-
112
- def save_environment_changes_remote(environment)
113
- local_environment = load_environment_from_file(environment)
114
- remote_environment = load_remote_environment(environment)
115
- @environment_diffs ||= Hash.new
116
- @environment_diffs["#{environment}"] = environment_diff(local_environment, remote_environment)
117
-
118
- version_change_threshold = spork_config.version_change_threshold || 2
119
- env_constraints_diff = constraints_diff(@environment_diffs["#{environment}"]).select{|k,v| v > version_change_threshold}
120
-
121
- if env_constraints_diff.size !=0 then
122
- ui.warn 'You\'re about to promote a significant version number change to 1 or more cookbooks:'
123
- ui.warn @environment_diffs["#{environment}"].select{|k,v|env_constraints_diff.has_key?(k)}.collect{|k,v| "\t#{k}: #{v}"}.join("\n")
124
-
125
- begin
126
- ui.confirm('Are you sure you want to continue?')
127
- rescue SystemExit => e
128
- if e.status == 3
129
- ui.confirm("Would you like to reset your local #{environment}.json to match the remote server?")
130
- tmp = Chef::Environment.load(environment)
131
- save_environment_changes(environment, pretty_print_json(tmp))
132
- ui.info "#{environment}.json was reset"
133
- end
134
-
135
- raise
136
- end
137
- end
138
-
139
- if @environment_diffs["#{environment}"].size > 1
140
- ui.msg ""
141
- ui.warn "You're about to promote changes to several cookbooks at once:"
142
- ui.warn @environment_diffs["#{environment}"].collect{|k,v| "\t#{k}: #{v}"}.join("\n")
143
-
144
- begin
145
- ui.confirm('Are you sure you want to continue?')
146
- rescue SystemExit => e
147
- if e.status == 3
148
- ui.confirm("Would you like to reset your local #{environment}.json to match the remote server?")
149
- tmp = Chef::Environment.load(environment)
150
- save_environment_changes(environment, pretty_print_json(tmp))
151
- ui.info "#{environment}.json was reset"
152
- end
153
-
154
- raise
155
- end
156
- end
157
-
158
- local_environment.save
159
- end
160
-
161
- def promote(environment, cookbook_names)
162
- cookbook_names = [cookbook_names].flatten
163
-
164
- cookbook_names.each do |cookbook_name|
165
- validate_version!(config[:version])
166
- version = config[:version] || load_cookbook(cookbook_name).version
167
-
168
- ui.msg "Adding version constraint #{cookbook_name} = #{version}"
169
- update_version_constraints(environment, cookbook_name, version)
170
- end
171
- end
172
-
173
- def check_cookbook_uploaded(cookbook_name)
174
- validate_version!(config[:version])
175
- version = config[:version] || load_cookbook(cookbook_name).version
176
-
177
- api_endpoint = "cookbooks/#{cookbook_name}/#{version}"
178
-
179
- begin
180
- cookbooks = rest.get_rest(api_endpoint)
181
- rescue Net::HTTPServerException => e
182
- ui.error "#{cookbook_name}@#{version} does not exist on Chef Server! Upload the cookbook first by running:\n\n\tknife spork upload #{cookbook_name}\n\n"
183
- exit(1)
184
- end
185
- end
186
-
187
- def check_cookbook_latest(cookbook_name)
188
- validate_version!(config[:version])
189
- version = config[:version] || load_cookbook(cookbook_name).version
190
- cb_latest = Chef::CookbookVersion.load(cookbook_name).metadata.version
191
- # ui.msg "server: #{cb_latest} -- local: #{version}"
192
- if cb_latest > version
193
- ui.confirm "There is a later version of #{cookbook_name} on the chef server. Would you still like to promote version #{version}"
194
- end
195
- end
196
- end
197
- end
1
+ require 'chef/knife'
2
+
3
+ module KnifeSpork
4
+ class SporkPromote < Chef::Knife
5
+
6
+ deps do
7
+ require 'chef/exceptions'
8
+ require 'knife-spork/runner'
9
+ begin
10
+ require 'berkshelf'
11
+ rescue LoadError; end
12
+ end
13
+
14
+ banner 'knife spork promote ENVIRONMENT COOKBOOK (options)'
15
+
16
+ option :version,
17
+ :short => '-v',
18
+ :long => '--version VERSION',
19
+ :description => 'Set the environment\'s version constraint to the specified version',
20
+ :default => nil
21
+
22
+ option :remote,
23
+ :long => '--remote',
24
+ :description => 'Save the environment to the chef server in addition to the local JSON file',
25
+ :default => nil
26
+
27
+ option :cookbook_path,
28
+ :short => '-o PATH:PATH',
29
+ :long => '--cookbook-path PATH:PATH',
30
+ :description => 'A colon-separated path to look for cookbooks in',
31
+ :proc => lambda { |o| o.split(':') }
32
+
33
+ if defined?(::Berkshelf)
34
+ option :berksfile,
35
+ :short => '-b',
36
+ :long => '--berksfile BERKSFILE',
37
+ :description => 'Path to a Berksfile to operate off of',
38
+ :default => File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME)
39
+ end
40
+
41
+ def run
42
+ self.class.send(:include, KnifeSpork::Runner)
43
+ self.config = Chef::Config.merge!(config)
44
+
45
+ if @name_args.empty?
46
+ show_usage
47
+ ui.error("You must specify the cookbook and environment to promote to")
48
+ exit 1
49
+ end
50
+
51
+ # Temporary fix for #138 to allow Berkshelf functionality
52
+ # to be bypassed until #85 has been completed and Berkshelf 3 support added
53
+ unload_berkshelf_if_specified
54
+
55
+ #First load so plugins etc know what to work with
56
+ @environments, @cookbook = load_environments_and_cookbook
57
+
58
+ run_plugins(:before_promote)
59
+
60
+ #Reload cookbook and env in case a VCS plugin found updates
61
+ @environments, @cookbook = load_environments_and_cookbook
62
+
63
+ check_cookbook_uploaded(@cookbook)
64
+ check_cookbook_latest(@cookbook)
65
+
66
+ @environments.each do |e|
67
+ environment = load_environment_from_file(e)
68
+
69
+
70
+ promote(environment, @cookbook)
71
+
72
+ ui.msg "Saving changes to #{e}.json"
73
+
74
+ new_environment_json = pretty_print_json(environment.to_hash)
75
+ save_environment_changes(e, new_environment_json)
76
+
77
+ if config[:remote] || spork_config.always_promote_remote
78
+ ui.msg "Uploading #{environment.name}.json to Chef Server"
79
+ save_environment_changes_remote(e)
80
+ ui.info "Promotion complete at #{Time.now}!"
81
+ else
82
+ ui.info "Promotion complete. Don't forget to upload your changed #{environment.name}.json to Chef Server"
83
+ end
84
+ end
85
+ run_plugins(:after_promote_local)
86
+ if config[:remote] || spork_config.always_promote_remote
87
+ run_plugins(:after_promote_remote)
88
+ end
89
+ end
90
+
91
+ def update_version_constraints(environment, cookbook, new_version)
92
+ validate_version!(new_version)
93
+ if spork_config.preserve_constraint_operators
94
+
95
+ cb_version = environment.cookbook_versions[cookbook]
96
+ if cb_version
97
+ if cb_version.length > 0
98
+ constraint_operator = cb_version.split.first
99
+ else
100
+ constraint_operator = "="
101
+ end
102
+ ui.msg "Preserving existing version constraint operator: #{constraint_operator}"
103
+ else
104
+ constraint_operator = "="
105
+ end
106
+ else
107
+ constraint_operator = "="
108
+ end
109
+ environment.cookbook_versions[cookbook] = "#{constraint_operator} #{new_version}"
110
+ end
111
+
112
+ def save_environment_changes_remote(environment)
113
+ local_environment = load_environment_from_file(environment)
114
+ remote_environment = load_remote_environment(environment)
115
+ @environment_diffs ||= Hash.new
116
+ @environment_diffs["#{environment}"] = environment_diff(local_environment, remote_environment)
117
+
118
+ version_change_threshold = spork_config.version_change_threshold || 2
119
+ env_constraints_diff = constraints_diff(@environment_diffs["#{environment}"]).select{|k,v| v > version_change_threshold}
120
+
121
+ if env_constraints_diff.size !=0 then
122
+ ui.warn 'You\'re about to promote a significant version number change to 1 or more cookbooks:'
123
+ ui.warn @environment_diffs["#{environment}"].select{|k,v|env_constraints_diff.has_key?(k)}.collect{|k,v| "\t#{k}: #{v}"}.join("\n")
124
+
125
+ begin
126
+ ui.confirm('Are you sure you want to continue?')
127
+ rescue SystemExit => e
128
+ if e.status == 3
129
+ ui.confirm("Would you like to reset your local #{environment}.json to match the remote server?")
130
+ tmp = Chef::Environment.load(environment)
131
+ save_environment_changes(environment, pretty_print_json(tmp))
132
+ ui.info "#{environment}.json was reset"
133
+ end
134
+
135
+ raise
136
+ end
137
+ end
138
+
139
+ if @environment_diffs["#{environment}"].size > 1
140
+ ui.msg ""
141
+ ui.warn "You're about to promote changes to several cookbooks at once:"
142
+ ui.warn @environment_diffs["#{environment}"].collect{|k,v| "\t#{k}: #{v}"}.join("\n")
143
+
144
+ begin
145
+ ui.confirm('Are you sure you want to continue?')
146
+ rescue SystemExit => e
147
+ if e.status == 3
148
+ ui.confirm("Would you like to reset your local #{environment}.json to match the remote server?")
149
+ tmp = Chef::Environment.load(environment)
150
+ save_environment_changes(environment, pretty_print_json(tmp))
151
+ ui.info "#{environment}.json was reset"
152
+ end
153
+
154
+ raise
155
+ end
156
+ end
157
+
158
+ local_environment.save
159
+ end
160
+
161
+ def promote(environment, cookbook_names)
162
+ cookbook_names = [cookbook_names].flatten
163
+
164
+ cookbook_names.each do |cookbook_name|
165
+ validate_version!(config[:version])
166
+ version = config[:version] || load_cookbook(cookbook_name).version
167
+
168
+ ui.msg "Adding version constraint #{cookbook_name} = #{version}"
169
+ update_version_constraints(environment, cookbook_name, version)
170
+ end
171
+ end
172
+
173
+ def check_cookbook_uploaded(cookbook_name)
174
+ validate_version!(config[:version])
175
+ version = config[:version] || load_cookbook(cookbook_name).version
176
+
177
+ api_endpoint = "cookbooks/#{cookbook_name}/#{version}"
178
+
179
+ begin
180
+ cookbooks = rest.get_rest(api_endpoint)
181
+ rescue Net::HTTPServerException => e
182
+ ui.error "#{cookbook_name}@#{version} does not exist on Chef Server! Upload the cookbook first by running:\n\n\tknife spork upload #{cookbook_name}\n\n"
183
+ exit(1)
184
+ end
185
+ end
186
+
187
+ def check_cookbook_latest(cookbook_name)
188
+ validate_version!(config[:version])
189
+ version = config[:version] || load_cookbook(cookbook_name).version
190
+ cb_latest = Chef::CookbookVersion.load(cookbook_name).metadata.version
191
+ # ui.msg "server: #{cb_latest} -- local: #{version}"
192
+ if cb_latest > version
193
+ ui.confirm "There is a later version of #{cookbook_name} on the chef server. Would you still like to promote version #{version}"
194
+ end
195
+ end
196
+ end
197
+ end