chef-provisioning 0.19 → 0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +62 -32
  3. data/lib/chef/provider/load_balancer.rb +18 -8
  4. data/lib/chef/provider/machine.rb +11 -7
  5. data/lib/chef/provider/machine_batch.rb +8 -4
  6. data/lib/chef/provider/machine_execute.rb +1 -1
  7. data/lib/chef/provider/machine_image.rb +46 -14
  8. data/lib/chef/provisioning.rb +9 -1
  9. data/lib/chef/provisioning/chef_managed_entry_store.rb +128 -0
  10. data/lib/chef/provisioning/chef_run_data.rb +9 -16
  11. data/lib/chef/provisioning/convergence_strategy/install_cached.rb +25 -7
  12. data/lib/chef/provisioning/convergence_strategy/install_msi.rb +26 -8
  13. data/lib/chef/provisioning/convergence_strategy/install_sh.rb +28 -6
  14. data/lib/chef/provisioning/driver.rb +28 -21
  15. data/lib/chef/provisioning/load_balancer_spec.rb +6 -71
  16. data/lib/chef/provisioning/machine_image_spec.rb +34 -0
  17. data/lib/chef/provisioning/machine_spec.rb +23 -47
  18. data/lib/chef/provisioning/managed_entry.rb +121 -0
  19. data/lib/chef/provisioning/managed_entry_store.rb +136 -0
  20. data/lib/chef/provisioning/recipe_dsl.rb +0 -4
  21. data/lib/chef/provisioning/version.rb +1 -1
  22. data/lib/chef/resource/chef_data_bag_resource.rb +1 -2
  23. data/lib/chef/resource/load_balancer.rb +1 -0
  24. data/lib/chef/resource/machine.rb +1 -1
  25. data/lib/chef/resource/machine_batch.rb +2 -2
  26. data/lib/chef/resource/machine_execute.rb +2 -1
  27. metadata +7 -8
  28. data/lib/chef/provisioning/chef_image_spec.rb +0 -111
  29. data/lib/chef/provisioning/chef_load_balancer_spec.rb +0 -108
  30. data/lib/chef/provisioning/chef_machine_spec.rb +0 -83
  31. data/lib/chef/provisioning/image_spec.rb +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35d07c9ee156834b006ec670fa2ad4f9fdaa467d
4
- data.tar.gz: 746b88dd6944cdf449513dee69ef5c8bbfdb91a8
3
+ metadata.gz: cef7f76f812dd3448e17029ab8f1a6ad7e6fbae0
4
+ data.tar.gz: c4eb855e69e250a2116b0cf76c86c9564f289e6d
5
5
  SHA512:
6
- metadata.gz: bf65fd08788dcb554a21f2cf75d7284bbe4e030abb2ea96d13b108e2f9be7a5f88927d2eafcc430746c5092888438eb2e4dfea32f2767242e99c1462c7744bac
7
- data.tar.gz: aa704ae71a32b3fd590d16e848a62d01d048c10570f5b60780da65da590aa54901fa5464572d3784f7451646e5901758b99eff47db14d7de59e479b3cef16fe3
6
+ metadata.gz: 84b90c58824627cfa6e867e6ec5bd6a4bd9537eabc2713206efcebb8132b30baf1eeb81baa21088ef901d2f411d1f7ed3fcb3d17a0ce969a9e49a720f24407ed
7
+ data.tar.gz: 9314c432528799c4f75b9d9821e1d9ce64dceecdb1ede33247b4c3b56d3f7e88ad7ed2b2e81002106a13a17c0b423cfeb49f1540aee09d2480b660e367a3877c
data/CHANGELOG.md CHANGED
@@ -1,29 +1,33 @@
1
1
  # Chef Provisioning Changelog
2
2
 
3
+ ## 0.20 (2/25/2015)
4
+
5
+ - Marking machines `nil` in a load_balancer does not affect existing machines ([#299][])
6
+ - `with_driver` now optionally accepts a block. If passed, it is only active in that block. If not passed, existing behavior is unchanged. ([#296][])
7
+ - New `show_output` attribute for `machine_execute`, defaults to false ([@causton1][])
8
+ - Changed `MachineSpec` storage to `ManagedEntry`. Driver authors, see PR for details ([#297][])
9
+ - If specifying exact chef version, don't re-install every chef-provisioning ([#303][])
10
+
3
11
  ## 0.19 (2/25/2015)
4
12
 
5
13
  - Support for different versions of Chef with the :chef_version and :prerelease arguments (`machine_options convergence_options: { chef_version: '12.0.1' }` or `prerelease: true`)
6
- - Support HTTPS proxy (@causton1)
14
+ - Support HTTPS proxy ([@causton1][])
7
15
  - Automatically configure HTTPS proxy when specifying `machine_options convergence_options: { http_proxy: '...' }`
8
16
  - Support for arbitrary configuration using `machine_options convergence_options: { chef_config: "anything you want dumped in /etc/chef/client.rb (will be appended to the standard options already placed in the file)" }`
9
17
 
10
- - Make load_balancer :destroy work (@lynchc)
11
- - Default to SSL for Chef install download (@xeon22)
12
- - Fix Chef overwriting attributes on first converge in `machine_batch` (#209)
13
- - Fix node permissions on Hosted / Enterprise Chef: no more adding your clients to the `admins` group (ewww). (#59)
14
- - Always pass an array (never nil) to the driver, even when there are no machines to add to it (partial fix for chef/chef-provisioning-aws#81)
15
- -
16
-
17
-
18
- 915eac3 (origin/jk/install-sh-version, jk/install-sh-version) Add chef_version, prerelease and install_sh_arguments to InstallSh
18
+ - Make load_balancer :destroy work ([@lynchc][])
19
+ - Default to SSL for Chef install download ([@xeon22][])
20
+ - Fix Chef overwriting attributes on first converge in `machine_batch` ([#209][])
21
+ - Fix node permissions on Hosted / Enterprise Chef: no more adding your clients to the `admins` group (ewww). ([#59][])
22
+ - Always pass an array (never nil) to the driver, even when there are no machines to add to it (partial fix for chef/chef-provisioning-aws[#81][])
19
23
 
20
24
  ## 0.18 (1/27/2015)
21
25
 
22
- - Allow `ssl_verify_mode` to be overridden (@mivok)
23
- - Support `machine_options[:convergence_options][:bootstrap_proxy]` (@mivok)
24
- - Allow `machine_options[:ssh_gateway]` without username (no @) (@mivok)
26
+ - Allow `ssl_verify_mode` to be overridden ([@mivok][])
27
+ - Support `machine_options[:convergence_options][:bootstrap_proxy]` ([@mivok][])
28
+ - Allow `machine_options[:ssh_gateway]` without username (no @) ([@mivok][])
25
29
  - Fix issue with net-ssh 2.9.2
26
- - Add `action :destroy` to `machine_image` (@miguelcnf)
30
+ - Add `action :destroy` to `machine_image` ([@miguelcnf][])
27
31
 
28
32
  ## 0.17 (12/17/2014)
29
33
 
@@ -68,7 +72,7 @@
68
72
 
69
73
  ## 0.14 (8/18/2014)
70
74
 
71
- - FEATURE: Add the machine_image resource (@jkeiser, @johnewart):
75
+ - FEATURE: Add the machine_image resource ([@jkeiser][], [@johnewart][]):
72
76
  ```ruby
73
77
  machine_image 'base' do
74
78
  machine_options :bootstrap_options => { :image_id => 'ami-1234798123431', :ssh_username => 'root' }
@@ -104,7 +108,7 @@
104
108
  - Creates a node with the name of the machine_image, which contains metadata
105
109
  like the username of the image. This makes things like AWS image registries
106
110
  possible.
107
- - Fix the no_converge convergence strategy (@johnewart)
111
+ - Fix the no_converge convergence strategy ([@johnewart][])
108
112
  - SSH port forwarding improvements:
109
113
  - Detects *any* IP on the localhost and forwards it--not just 127.0.0.1
110
114
  - Binds to localhost on the remote side instead of 127.0.0.1, allowing for IPv6 communication
@@ -114,8 +118,8 @@
114
118
 
115
119
  ## 0.13 (6/17/2014)
116
120
 
117
- - make winrm work again (@mwrock)
118
- - add bootstrap_proxy as a convergence_option for when target machines require a proxy (@MrMMorris)
121
+ - make winrm work again ([@mwrock][])
122
+ - add bootstrap_proxy as a convergence_option for when target machines require a proxy ([@MrMMorris][])
119
123
 
120
124
  ## 0.12.1 (6/18/2014)
121
125
 
@@ -125,8 +129,8 @@
125
129
  ## 0.12 (6/18/2014)
126
130
 
127
131
  - Remove chef-provisioning-fog and chef-provisioning-vagrant as dependencies (install whatever things you want directly!)
128
- - Fix ssl_verify_mode to work correctly when other HTTPS calls are made (@mwrock)
129
- - Fix machine_file and machine_execute resources (@irvingpop)
132
+ - Fix ssl_verify_mode to work correctly when other HTTPS calls are made ([@mwrock][])
133
+ - Fix machine_file and machine_execute resources ([@irvingpop][])
130
134
 
131
135
  ## 0.11.2 (6/4/2014)
132
136
 
@@ -143,8 +147,8 @@
143
147
  - get rid of annoying SSL warning (note: this turns off SSL verification, which was the default anyway)
144
148
  - fix machine_batch error report to be less verbose
145
149
  - fail when machine is being moved from driver to driver
146
- - @marcusn disconnect from SSH when there is a problem
147
- - fix SSH gateway code to honor any options given (@marcusn)
150
+ - [@marcusn][] disconnect from SSH when there is a problem
151
+ - fix SSH gateway code to honor any options given ([@marcusn][])
148
152
  - Make machine_batch auto batching smarter (only batch things that have the same actions)
149
153
  - Allow auto batching to be turned off with `auto_batch_machines = false` in recipes or config
150
154
  - Allow this:
@@ -197,8 +201,8 @@
197
201
  ## 0.9 (4/9/2014)
198
202
 
199
203
  - Add `files` and `file` attributes to the `machine` resource
200
- - Fix `machine_execute` resource (@irvingpop)
201
- - Fix `machine :converge` action (thanks @double-z)
204
+ - Fix `machine_execute` resource ([@irvingpop][])
205
+ - Fix `machine :converge` action (thanks [@double-z][])
202
206
  - Make chef-client timeout longer by default (2 hours)
203
207
  - Make chef_client_timeout a configurable option for all convergence strategies and provisioner_options
204
208
  - Add `metal cp` command
@@ -207,7 +211,7 @@
207
211
 
208
212
  - Add timeout support to execute
209
213
  - Fix machine_file resource
210
- - Add ohai_hints DSL to machine resource (@xorl)
214
+ - Add ohai_hints DSL to machine resource ([@xorl][])
211
215
 
212
216
  ## 0.8.1 (4/9/2014)
213
217
 
@@ -219,7 +223,7 @@
219
223
 
220
224
  ## 0.8 (4/8/2014)
221
225
 
222
- - New machine_execute resource! (irving@chef.io)
226
+ - New machine_execute resource! (irving[@chef][].io)
223
227
  - Experimental "metal" command line: metal execute NODENAME COMMAND ARGS
224
228
  - Transport: Add ability to stream execute() for better nested chef-client debugging
225
229
 
@@ -234,23 +238,49 @@
234
238
 
235
239
  ## 0.5 (4/3/2014)
236
240
 
237
- * Provisioner interface changes designed to allow provisioners to be used outside of Chef (doubt@chef.io)
241
+ * Provisioner interface changes designed to allow provisioners to be used outside of Chef (doubt[@chef][].io)
238
242
  * All Provisioner and Machine methods now take "action_handler" instead of "driver." It uses the ActionHandler interface described in action_handler.rb. In short:
239
243
  - driver.run_context -> action_handler.recipe_context
240
244
  - driver.updated_by_last_action(true) -> action_handler.updated!
241
245
  - driver.converge_by -> action_handler.perform_action
242
246
  - driver.cookbook_name -> driver.debug_name
243
247
  * Convergence strategy: delete_chef_objects() -> cleanup_convergence()
244
- * Ability to get back to a machine from a node (another Provisioner interface change) (doubt@chef.io):
248
+ * Ability to get back to a machine from a node (another Provisioner interface change) (doubt[@chef][].io):
245
249
  * Provisioners must create a file named `chef_provisioning/provisioner_init/<scheme>_init.rb`. It will be required when a node is encountered with that scheme. It should call Chef::Provisioning.add_registered_provisioner_class(<scheme>, <provisioner class name>). For the provisioner_url `fog:AWS:21348723432`, the scheme is "fog" and the file is `chef_provisioningprovisioner_init/fog_init.rb`. It should call `Chef::Provisioning.add_registered_provisioner_class('fog', Chef::Provisioning::Provisioner::FogProvisioner)`.
246
250
  * Provisioner classes must implement the class method `inflate(node)`, which should create a Provisioner instance appropriate to the given `node` (generally by looking at `node['normal']['provisioner_output']`)
247
251
  * New `NoConverge` convergence strategy that creates a node but does not install Chef or converge.
248
- * Support for machine_file `group`, `owner` and `mode` attributes (@irvingpop)
249
- * SSH transport (ryan@segv.net): try to enable pty when possible (increases chance of successful connection). Set options[:ssh_pty_enable] to `false` to turn this off. Set `true` to force it (and fail if we can't get it)
252
+ * Support for machine_file `group`, `owner` and `mode` attributes ([@irvingpop][])
253
+ * SSH transport (ryan[@segv][].net): try to enable pty when possible (increases chance of successful connection). Set options[:ssh_pty_enable] to `false` to turn this off. Set `true` to force it (and fail if we can't get it)
250
254
 
251
255
  ## 0.4 (3/29/2014)
252
256
 
253
257
  * EC2: Make it possible for multiple IAM users to converge chef-provisioning on the same account
254
- * Openstack: Openstack support via the Fog driver! (@cstewart87)
255
- * EC2: Add :use_private_ip_for_ssh option, and use private ip by default if public IP does not exist. (@xorl, @dafyddcrosby)
258
+ * Openstack: Openstack support via the Fog driver! ([@cstewart87][])
259
+ * EC2: Add :use_private_ip_for_ssh option, and use private ip by default if public IP does not exist. ([@xorl][], [@dafyddcrosby][])
256
260
  * RHEL/Centos: fix platform detection and installation
261
+
262
+ <!--- The following link definition list is generated by PimpMyChangelog --->
263
+ [#59]: https://github.com/chef/chef-provisioning/issues/59
264
+ [#81]: https://github.com/chef/chef-provisioning/issues/81
265
+ [#209]: https://github.com/chef/chef-provisioning/issues/209
266
+ [#296]: https://github.com/chef/chef-provisioning/issues/296
267
+ [#297]: https://github.com/chef/chef-provisioning/issues/297
268
+ [#299]: https://github.com/chef/chef-provisioning/issues/299
269
+ [#303]: https://github.com/chef/chef-provisioning/issues/303
270
+ [@MrMMorris]: https://github.com/MrMMorris
271
+ [@causton1]: https://github.com/causton1
272
+ [@chef]: https://github.com/chef
273
+ [@cstewart87]: https://github.com/cstewart87
274
+ [@dafyddcrosby]: https://github.com/dafyddcrosby
275
+ [@double-z]: https://github.com/double-z
276
+ [@irvingpop]: https://github.com/irvingpop
277
+ [@jkeiser]: https://github.com/jkeiser
278
+ [@johnewart]: https://github.com/johnewart
279
+ [@lynchc]: https://github.com/lynchc
280
+ [@marcusn]: https://github.com/marcusn
281
+ [@miguelcnf]: https://github.com/miguelcnf
282
+ [@mivok]: https://github.com/mivok
283
+ [@mwrock]: https://github.com/mwrock
284
+ [@segv]: https://github.com/segv
285
+ [@xeon22]: https://github.com/xeon22
286
+ [@xorl]: https://github.com/xorl
@@ -2,7 +2,6 @@ require 'chef/provider/lwrp_base'
2
2
  require 'chef/provider/chef_node'
3
3
  require 'openssl'
4
4
  require 'chef/provisioning/chef_provider_action_handler'
5
- require 'chef/provisioning/chef_load_balancer_spec'
6
5
 
7
6
  class Chef
8
7
  class Provider
@@ -20,12 +19,17 @@ class Chef
20
19
  @new_driver ||= run_context.chef_metal.driver_for(new_resource.driver)
21
20
  end
22
21
 
22
+ def chef_managed_entry_store
23
+ @chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
24
+ end
25
+
23
26
  action :create do
24
- lb_spec = Chef::Provisioning::ChefLoadBalancerSpec.get(new_resource.name) ||
25
- Chef::Provisioning::ChefLoadBalancerSpec.empty(new_resource.name)
27
+ lb_spec = chef_managed_entry_store.get_or_new(:load_balancer, new_resource.name)
26
28
 
27
29
  Chef::Log.debug "Creating load balancer: #{new_resource.name}; loaded #{lb_spec.inspect}"
28
- machine_specs = new_resource.machines ? new_resource.machines.map { |machine| get_machine_spec(machine) } : []
30
+ if new_resource.machines
31
+ machine_specs = new_resource.machines.map { |machine| get_machine_spec!(machine) }
32
+ end
29
33
 
30
34
  new_driver.allocate_load_balancer(action_handler, lb_spec, lb_options, machine_specs)
31
35
  lb_spec.save(action_handler)
@@ -33,14 +37,17 @@ class Chef
33
37
  end
34
38
 
35
39
  action :destroy do
36
- lb_spec = Chef::Provisioning::ChefLoadBalancerSpec.get(new_resource.name)
37
- new_driver.destroy_load_balancer(action_handler, lb_spec, lb_options)
40
+ lb_spec = chef_managed_entry_store.get(:load_balancer, new_resource.name)
41
+ if lb_spec
42
+ new_driver.destroy_load_balancer(action_handler, lb_spec, lb_options)
43
+ end
38
44
  end
39
45
 
40
46
  private
41
- def get_machine_spec(machine_name)
47
+
48
+ def get_machine_spec!(machine_name)
42
49
  Chef::Log.debug "Getting machine spec for #{machine_name}"
43
- Chef::Provisioning::ChefMachineSpec.get(machine_name)
50
+ Provisioning.chef_managed_entry_store(new_resource.chef_server).get!(:machine, machine_name)
44
51
  end
45
52
 
46
53
  def lb_options
@@ -50,3 +57,6 @@ class Chef
50
57
  end
51
58
  end
52
59
  end
60
+
61
+ require 'chef/provisioning/chef_managed_entry_store'
62
+ Chef::Provisioning::ChefManagedEntryStore.type_names_for_backcompat[:load_balancer] = "loadbalancers"
@@ -2,7 +2,6 @@ require 'chef/provider/lwrp_base'
2
2
  require 'chef/provider/chef_node'
3
3
  require 'openssl'
4
4
  require 'chef/provisioning/chef_provider_action_handler'
5
- require 'chef/provisioning/chef_machine_spec'
6
5
 
7
6
  class Chef
8
7
  class Provider
@@ -11,6 +10,9 @@ class Machine < Chef::Provider::LWRPBase
11
10
  def action_handler
12
11
  @action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
13
12
  end
13
+ def action_handler=(value)
14
+ @action_handler = value
15
+ end
14
16
 
15
17
  use_inline_resources
16
18
 
@@ -26,6 +28,8 @@ class Machine < Chef::Provider::LWRPBase
26
28
  raise "Cannot move '#{machine_spec.name}' from #{current_driver.driver_url} to #{new_driver.driver_url}: machine moving is not supported. Destroy and recreate."
27
29
  end
28
30
  new_driver.allocate_machine(action_handler, machine_spec, new_machine_options)
31
+ machine_spec.from_image ||= new_resource.from_image if new_resource.from_image
32
+ machine_spec.driver_url ||= new_driver.driver_url
29
33
  machine_spec.save(action_handler)
30
34
  end
31
35
 
@@ -107,7 +111,7 @@ class Machine < Chef::Provider::LWRPBase
107
111
  def from_image_spec
108
112
  @from_image_spec ||= begin
109
113
  if new_resource.from_image
110
- Chef::Provisioning::ChefImageSpec.get(new_resource.from_image, new_resource.chef_server)
114
+ chef_managed_entry_store.get!(:machine_image, new_resource.from_image)
111
115
  else
112
116
  nil
113
117
  end
@@ -125,10 +129,6 @@ class Machine < Chef::Provider::LWRPBase
125
129
  def machine_options(driver)
126
130
  configs = []
127
131
 
128
- if from_image_spec && from_image_spec.machine_options
129
- configs << from_image_spec.machine_options
130
- end
131
-
132
132
  configs << {
133
133
  :convergence_options =>
134
134
  [ :chef_server,
@@ -155,7 +155,11 @@ class Machine < Chef::Provider::LWRPBase
155
155
  node_driver.load_current_resource
156
156
  json = node_driver.new_json
157
157
  json['normal']['chef_provisioning'] = node_driver.current_json['normal']['chef_provisioning']
158
- @machine_spec = Chef::Provisioning::ChefMachineSpec.new(json, new_resource.chef_server)
158
+ @machine_spec = chef_managed_entry_store.new_entry(:machine, new_resource.name, json)
159
+ end
160
+
161
+ def chef_managed_entry_store
162
+ @chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
159
163
  end
160
164
 
161
165
  def self.upload_files(action_handler, machine, files)
@@ -4,7 +4,6 @@ require 'chef/provider/machine'
4
4
  require 'chef/provisioning/chef_provider_action_handler'
5
5
  require 'chef/provisioning/add_prefix_action_handler'
6
6
  require 'chef/provisioning/machine_spec'
7
- require 'chef/provisioning/chef_machine_spec'
8
7
 
9
8
  class Chef
10
9
  class Provider
@@ -28,6 +27,8 @@ class MachineBatch < Chef::Provider::LWRPBase
28
27
  by_new_driver.each do |driver, specs_and_options|
29
28
  driver.allocate_machines(action_handler, specs_and_options, parallelizer) do |machine_spec|
30
29
  m = by_id[machine_spec.id]
30
+ machine_spec.from_image ||= m[:resource].from_image if m[:resource] && m[:resource].from_image
31
+ machine_spec.driver_url ||= driver.driver_url
31
32
  machine_spec.save(m[:action_handler])
32
33
  end
33
34
  end
@@ -168,7 +169,7 @@ class MachineBatch < Chef::Provider::LWRPBase
168
169
  :machine_options => proc { |driver| provider.machine_options(driver) },
169
170
  :action_handler => Provisioning::AddPrefixActionHandler.new(action_handler, "[#{machine_resource.name}] ")
170
171
  }
171
- elsif machine.is_a?(Provisioning::MachineSpec)
172
+ elsif machine.is_a?(Provisioning::ManagedEntry)
172
173
  machine_spec = machine
173
174
  {
174
175
  :spec => machine_spec,
@@ -179,8 +180,7 @@ class MachineBatch < Chef::Provider::LWRPBase
179
180
  }
180
181
  else
181
182
  name = machine
182
- machine_spec = Provisioning::ChefMachineSpec.get(name, new_resource.chef_server) ||
183
- Provisioning::ChefMachineSpec.empty(name, new_resource.chef_server)
183
+ machine_spec = chef_managed_entry_store.get_or_new(:machine, name)
184
184
  {
185
185
  :spec => machine_spec,
186
186
  :desired_driver => new_resource.driver,
@@ -192,6 +192,10 @@ class MachineBatch < Chef::Provider::LWRPBase
192
192
  end.to_a
193
193
  end
194
194
 
195
+ def chef_managed_entry_store
196
+ @chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
197
+ end
198
+
195
199
  def machine_options(driver)
196
200
  result = { :convergence_options => { :chef_server => new_resource.chef_server } }
197
201
  result = Chef::Mixin::DeepMerge.hash_only_merge(result, run_context.chef_provisioning.config[:machine_options]) if run_context.chef_provisioning.config[:machine_options]
@@ -27,7 +27,7 @@ class MachineExecute < Chef::Provider::LWRPBase
27
27
  end
28
28
 
29
29
  action :run do
30
- machine.execute(action_handler, new_resource.command)
30
+ machine.execute(action_handler, new_resource.command, :stream => new_resource.live_stream)
31
31
  end
32
32
 
33
33
  end
@@ -2,7 +2,6 @@ require 'chef/provider/lwrp_base'
2
2
  require 'chef/provider/chef_node'
3
3
  require 'openssl'
4
4
  require 'chef/provisioning/chef_provider_action_handler'
5
- require 'chef/provisioning/chef_image_spec'
6
5
 
7
6
  class Chef
8
7
  class Provider
@@ -20,49 +19,82 @@ class MachineImage < Chef::Provider::LWRPBase
20
19
  @new_driver ||= run_context.chef_provisioning.driver_for(new_resource.driver)
21
20
  end
22
21
 
22
+ def chef_managed_entry_store
23
+ @chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
24
+ end
25
+
23
26
  action :create do
24
27
  # Get the image mapping on the server (from name to image-id)
25
- image_spec = Chef::Provisioning::ChefImageSpec.get(new_resource.name, new_resource.chef_server) ||
26
- Chef::Provisioning::ChefImageSpec.empty(new_resource.name, new_resource.chef_server)
27
- if image_spec.location
28
+ image_spec = chef_managed_entry_store.get_or_new(:machine_image, new_resource.name)
29
+ if image_spec.reference
28
30
  # TODO check for real existence and maybe update
29
31
  else
30
32
  #
31
33
  # Create a new image
32
34
  #
33
- image_spec.machine_options = new_resource.machine_options
34
- create_image(image_spec)
35
+ create_image(image_spec, new_resource.machine_options || {})
35
36
  end
36
37
  end
37
38
 
38
39
  action :destroy do
40
+ # Destroy the exemplar machine if it exists
41
+ machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
42
+ machine_provider.action_handler = action_handler
43
+ machine_provider.load_current_resource
44
+ machine_provider.action_destroy
45
+
39
46
  # Get the image mapping on the server (from name to image-id)
40
- image_spec = Chef::Provisioning::ChefImageSpec.get(new_resource.name, new_resource.chef_server) ||
41
- Chef::Provisioning::ChefImageSpec.empty(new_resource.name, new_resource.chef_server)
47
+ image_spec = chef_managed_entry_store.get(:machine_image, new_resource.name)
42
48
 
43
- if image_spec.location
49
+ if image_spec && image_spec.reference
44
50
  new_driver.destroy_image(action_handler, image_spec, new_resource.image_options)
45
51
  image_spec.delete(action_handler)
46
52
  end
47
53
  end
48
54
 
49
- def create_image(image_spec)
55
+ def create_image(image_spec, machine_options)
50
56
  # 1. Create the exemplar machine
51
57
  machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
58
+ machine_provider.action_handler = action_handler
52
59
  machine_provider.load_current_resource
53
60
  machine_provider.action_converge
54
61
 
55
62
  # 2. Create the image
56
- new_driver.allocate_image(action_handler, image_spec, new_resource.image_options,
57
- machine_provider.machine_spec)
63
+ machine_options = new_machine_options
64
+ begin
65
+ new_driver.allocate_image(action_handler, image_spec, new_image_options,
66
+ machine_provider.machine_spec, machine_options)
67
+ rescue ArgumentError
68
+ # Backcompat kludge - remove in later version.
69
+ Chef::Log.warn("Driver #{new_driver.driver_url} does not accept machine_options. This will be deprecated before Provisioning 1.0.")
70
+ machine_provider.machine_spec.instance_eval { @machine_options = machine_options }
71
+ new_driver.allocate_image(action_handler, image_spec, new_image_options,
72
+ machine_provider.machine_spec)
73
+ end
74
+ image_spec.driver_url ||= new_driver.driver_url
75
+ image_spec.from_image ||= new_resource.from_image if new_resource.from_image
76
+ image_spec.run_list ||= machine_provider.machine_spec.node['run_list']
58
77
 
59
78
  # 3. Save the linkage from name -> image id
60
79
  image_spec.save(action_handler)
61
80
 
62
81
  # 4. Wait for image to be ready
63
- new_driver.ready_image(action_handler, image_spec, new_resource.image_options)
82
+ new_driver.ready_image(action_handler, image_spec, new_image_options)
83
+
84
+ machine_provider.action_destroy
64
85
  end
65
86
 
87
+ def new_image_options
88
+ @new_image_options ||= (new_resource.image_options || {}).to_hash.dup
89
+ end
90
+
91
+ def new_machine_options
92
+ @new_machine_options ||= (new_resource.machine_options || {}).to_hash.dup
93
+ end
94
+
95
+ end
66
96
  end
67
97
  end
68
- end
98
+
99
+ require 'chef/provisioning/chef_managed_entry_store'
100
+ Chef::Provisioning::ChefManagedEntryStore.type_names_for_backcompat[:machine_image] = "images"