chef-metal 0.10.2 → 0.11.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -5
  3. data/README.md +3 -3
  4. data/bin/metal +5 -9
  5. data/lib/chef/provider/machine.rb +81 -32
  6. data/lib/chef/provider/machine_batch.rb +67 -58
  7. data/lib/chef/provider/machine_execute.rb +7 -7
  8. data/lib/chef/provider/machine_file.rb +11 -11
  9. data/lib/chef/resource/machine.rb +11 -15
  10. data/lib/chef/resource/machine_batch.rb +1 -1
  11. data/lib/chef/resource/machine_execute.rb +3 -4
  12. data/lib/chef/resource/machine_file.rb +3 -4
  13. data/lib/chef_metal.rb +26 -28
  14. data/lib/chef_metal/action_handler.rb +9 -7
  15. data/lib/chef_metal/add_prefix_action_handler.rb +7 -5
  16. data/lib/chef_metal/chef_machine_spec.rb +64 -0
  17. data/lib/chef_metal/{provider_action_handler.rb → chef_provider_action_handler.rb} +27 -14
  18. data/lib/chef_metal/chef_run_data.rb +68 -7
  19. data/lib/chef_metal/convergence_strategy.rb +14 -3
  20. data/lib/chef_metal/convergence_strategy/install_cached.rb +24 -10
  21. data/lib/chef_metal/convergence_strategy/install_msi.rb +17 -10
  22. data/lib/chef_metal/convergence_strategy/install_sh.rb +20 -10
  23. data/lib/chef_metal/convergence_strategy/no_converge.rb +20 -13
  24. data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +51 -47
  25. data/lib/chef_metal/{provider.rb → driver.rb} +103 -79
  26. data/lib/chef_metal/machine.rb +13 -5
  27. data/lib/chef_metal/machine/basic_machine.rb +11 -11
  28. data/lib/chef_metal/machine/unix_machine.rb +6 -6
  29. data/lib/chef_metal/machine/windows_machine.rb +3 -3
  30. data/lib/chef_metal/machine_spec.rb +22 -25
  31. data/lib/chef_metal/recipe_dsl.rb +34 -9
  32. data/lib/chef_metal/transport.rb +7 -2
  33. data/lib/chef_metal/transport/ssh.rb +42 -9
  34. data/lib/chef_metal/transport/winrm.rb +8 -5
  35. data/lib/chef_metal/version.rb +1 -1
  36. data/spec/integration/machine.rb +29 -0
  37. metadata +21 -9
  38. data/lib/chef_metal/aws_credentials.rb +0 -58
  39. data/lib/chef_metal/openstack_credentials.rb +0 -44
  40. data/lib/chef_metal/provisioner.rb +0 -121
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af79447510d93b295a7d77a3223d670bdc569415
4
- data.tar.gz: ac28faf8d8afa3026960b9997de94d9c4fc77369
3
+ metadata.gz: 544a8fd4658a8ad73c179ddd5f804440cb7f3f8e
4
+ data.tar.gz: ac8690681f379ae779bbc4b7b26d4c68281ec359
5
5
  SHA512:
6
- metadata.gz: 49762ba3a7f0f71677b85d6f9657cdb05174c1d389ba96825bb218f9af7dd557f35ab515dd391865caba7dc20a6a3ddfbd12b1a3c566219bab1e6cda7d8248fa
7
- data.tar.gz: 5412dfb1f503aa30259bf37c16a7f8e46dffc98c7434375fefaf208a3745af25208052d60a4982a6a809444eaaeb82211e6490fa5a9c52cced6a7347cf70c0a0
6
+ metadata.gz: d0f8d6f2f781e577898413a3bcc2cd6c9493dc592b11144ab1764b27f4c1fd5eca28c34571befb510a99790659feb03a0a7c5435cb244a55e262c762414ce041
7
+ data.tar.gz: 7575521c82702f2be0a9d82a840f71794d63ec3b417c371c8e0fa937452dbdaceb4a881d70f45123a8f73592a46524ce5ab37ef35daf8b69c22eb69fe64f91b1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Chef Metal Changelog
2
2
 
3
+ ## 0.11.beta (5/23/2014)
4
+
5
+ - New Driver interface (see docs/ and blogs/ directories for documentation)
6
+
3
7
  ## 0.10.2 (5/2/2014)
4
8
 
5
9
  - Fix crash with add_provisioner_options when provisioner_options is not yet set
@@ -72,11 +76,11 @@
72
76
  ## 0.5 (4/3/2014)
73
77
 
74
78
  * Provisioner interface changes designed to allow provisioners to be used outside of Chef (doubt@getchef.com)
75
- * All Provisioner and Machine methods now take "action_handler" instead of "provider." It uses the ActionHandler interface described in action_handler.rb. In short:
76
- - provider.run_context -> action_handler.recipe_context
77
- - provider.updated_by_last_action(true) -> action_handler.updated!
78
- - provider.converge_by -> action_handler.perform_action
79
- - provider.cookbook_name -> provider.debug_name
79
+ * All Provisioner and Machine methods now take "action_handler" instead of "driver." It uses the ActionHandler interface described in action_handler.rb. In short:
80
+ - driver.run_context -> action_handler.recipe_context
81
+ - driver.updated_by_last_action(true) -> action_handler.updated!
82
+ - driver.converge_by -> action_handler.perform_action
83
+ - driver.cookbook_name -> driver.debug_name
80
84
  * Convergence strategy: delete_chef_objects() -> cleanup_convergence()
81
85
  * Ability to get back to a machine from a node (another Provisioner interface change) (doubt@getchef.com):
82
86
  * Provisioners must create a file named `chef_metal/provisioner_init/<scheme>_init.rb`. It will be required when a node is encountered with that scheme. It should call ChefMetal.add_registered_provisioner_class(<scheme>, <provisioner class name>). For the provisioner_url `fog:AWS:21348723432`, the scheme is "fog" and the file is `chef_metalprovisioner_init/fog_init.rb`. It should call `ChefMetal.add_registered_provisioner_class('fog', ChefMetal::Provisioner::FogProvisioner)`.
data/README.md CHANGED
@@ -89,7 +89,7 @@ Provisioners each have their own repository. Current provisioners:
89
89
 
90
90
  ### Vagrant
91
91
 
92
- chef-zero comes with a provisioner for Vagrant, an abstraction that covers VirtualBox, VMWare and other Virtual Machine providers. To run it, you can check out the sample recipes with:
92
+ chef-zero comes with a provisioner for Vagrant, an abstraction that covers VirtualBox, VMWare and other Virtual Machine drivers. To run it, you can check out the sample recipes with:
93
93
 
94
94
  ```
95
95
  chef-client -z -o myapp::vagrant,myapp::linux,myapp::small
@@ -144,7 +144,7 @@ end
144
144
 
145
145
  ### Fog (EC2 and friends)
146
146
 
147
- chef-metal also comes with a [Fog](http://fog.io/) provisioner that handles provisioning to Amazon's EC2 and other cloud providers. (Only EC2 has been tested so far.) Before you begin, you will need to put your AWS credentials in ~/.aws/config in the format [mentioned in Option 1 here](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#d0e726).
147
+ chef-metal also comes with a [Fog](http://fog.io/) provisioner that handles provisioning to Amazon's EC2 and other cloud drivers. (Only EC2 has been tested so far.) Before you begin, you will need to put your AWS credentials in ~/.aws/config in the format [mentioned in Option 1 here](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#d0e726).
148
148
 
149
149
  Once your credentials are in, basic usage looks like this:
150
150
 
@@ -159,7 +159,7 @@ ec2testdir = File.expand_path('~/ec2test')
159
159
 
160
160
  directory ec2testdir
161
161
 
162
- with_fog_ec2_provisioner # :provider => 'AWS'
162
+ with_fog_ec2_provisioner # :driver => 'AWS'
163
163
 
164
164
  with_provisioner_options :image_id => 'ami-5ee70037'
165
165
 
data/bin/metal CHANGED
@@ -134,22 +134,22 @@ class ChefMetal::Application < Chef::Application
134
134
  end
135
135
  when 'converge'
136
136
  each_machine(cli_arguments.shift) do |machine, provisioner|
137
- machine.converge(action_handler, chef_server)
137
+ machine.converge(action_handler)
138
138
  end
139
139
  when 'delete'
140
140
  each_machine(cli_arguments.shift) do |machine, provisioner|
141
- provisioner.delete_machine(action_handler, machine.node)
141
+ provisioner.delete_machine(action_handler, machine.machine_spec)
142
142
  end
143
143
  when 'update'
144
144
  each_machine(cli_arguments.shift) do |machine, provisioner|
145
- machine = provisioner.acquire_machine(action_handler, machine.node)
145
+ machine = provisioner.acquire_machine(action_handler, machine.machine_spec)
146
146
  # TODO find out what files were uploaded so we can do it again
147
147
  machine.setup_convergence(action_handler)
148
- machine.converge(action_handler, chef_server)
148
+ machine.converge(action_handler)
149
149
  end
150
150
  when 'stop'
151
151
  each_machine(cli_arguments.shift) do |machine, provisioner|
152
- provisioner.stop_machine(action_handler, machine.node)
152
+ provisioner.stop_machine(action_handler, machine.machine_spec)
153
153
  end
154
154
  when 'cat'
155
155
  each_machine(cli_arguments.shift) do |machine, provisioner|
@@ -242,10 +242,6 @@ class ChefMetal::Application < Chef::Application
242
242
  Chef::RunContext.new(node, {},
243
243
  Chef::EventDispatch::Dispatcher.new(Chef::Formatters::Doc.new(STDOUT,STDERR)))
244
244
  end
245
-
246
- def debug_name
247
- 'metal'
248
- end
249
245
  end
250
246
  end
251
247
 
@@ -1,11 +1,14 @@
1
1
  require 'chef/provider/lwrp_base'
2
2
  require 'chef/provider/chef_node'
3
3
  require 'openssl'
4
- require 'chef_metal/provider_action_handler'
4
+ require 'chef_metal/chef_provider_action_handler'
5
+ require 'chef_metal/chef_machine_spec'
5
6
 
6
7
  class Chef::Provider::Machine < Chef::Provider::LWRPBase
7
8
 
8
- include ChefMetal::ProviderActionHandler
9
+ def action_handler
10
+ @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
11
+ end
9
12
 
10
13
  use_inline_resources
11
14
 
@@ -13,59 +16,105 @@ class Chef::Provider::Machine < Chef::Provider::LWRPBase
13
16
  true
14
17
  end
15
18
 
16
- action :create do
17
- node_json = node_provider.new_json
18
- node_json['normal']['provisioner_options'] = new_resource.provisioner_options
19
- # Preserve provisioner_output, whatever the cost
20
- node_json['normal']['provisioner_output'] = node_provider.current_json['normal']['provisioner_output']
21
- machine = new_resource.provisioner.acquire_machine(self, node_json)
19
+ action :allocate do
20
+ new_driver.allocate_machine(action_handler, machine_spec, machine_options)
21
+ machine_spec.save(action_handler)
22
+ end
23
+
24
+ action :ready do
25
+ action_allocate
26
+ machine = current_driver.ready_machine(action_handler, machine_spec, machine_options)
27
+ end
28
+
29
+ action :setup do
30
+ machine = action_ready
31
+ begin
32
+ machine.setup_convergence(action_handler)
33
+ upload_files(machine)
34
+ ensure
35
+ machine.disconnect
36
+ end
37
+ end
38
+
39
+ action :converge do
40
+ machine = action_ready
22
41
  begin
23
- machine.setup_convergence(self, new_resource)
42
+ machine.setup_convergence(action_handler)
24
43
  upload_files(machine)
25
44
  # If we were asked to converge, or anything changed, or if a converge has never succeeded, converge.
26
45
  if new_resource.converge || (new_resource.converge.nil? && resource_updated?) ||
27
- !node_json['automatic'] || node_json['automatic'].size == 0
28
- machine.converge(self, new_resource.chef_server)
46
+ !machine_spec.node['automatic'] || machine_spec.node['automatic'].size == 0
47
+ machine.converge(action_handler)
29
48
  end
30
49
  ensure
31
50
  machine.disconnect
32
51
  end
33
52
  end
34
53
 
35
- action :converge do
36
- node_json = node_provider.new_json
37
- node_json['normal']['provisioner_options'] = new_resource.provisioner_options
38
- # Preserve provisioner_output, whatever the cost
39
- node_json['normal']['provisioner_output'] = node_provider.current_json['normal']['provisioner_output']
40
- machine = new_resource.provisioner.connect_to_machine(node_json)
54
+ action :converge_only do
55
+ machine = run_context.chef_metal.connect_to_machine(machine_spec, machine_options)
41
56
  begin
42
- machine.converge(self, new_resource.chef_server)
57
+ machine.converge(action_handler)
43
58
  ensure
44
59
  machine.disconnect
45
60
  end
46
61
  end
47
62
 
48
63
  action :stop do
49
- node_json = node_provider.new_json
50
- node_json['normal']['provisioner_options'] = new_resource.provisioner_options
51
- # Preserve provisioner_output, whatever the cost
52
- node_json['normal']['provisioner_output'] = node_provider.current_json['normal']['provisioner_output']
53
- new_resource.provisioner.stop_machine(self, node_json)
64
+ if current_driver
65
+ current_driver.stop_machine(action_handler, machine_spec, machine_options)
66
+ end
67
+ end
68
+
69
+ action :destroy do
70
+ if current_driver
71
+ current_driver.destroy_machine(action_handler, machine_spec, machine_options)
72
+ end
73
+ end
74
+
75
+ def new_driver
76
+ run_context.chef_metal.driver_for(new_resource.driver)
54
77
  end
55
78
 
56
- action :delete do
57
- # Grab the node json by asking the provider for it
58
- node_data = node_provider.current_json
79
+ def new_driver_config
80
+ run_context.chef_metal.driver_config_for(new_resource.driver)
81
+ end
59
82
 
60
- # Destroy the machine
61
- new_resource.provisioner.delete_machine(self, node_data)
83
+ def current_driver
84
+ if machine_spec.driver_url
85
+ run_context.chef_metal.driver_for_url(machine_spec.driver_url)
86
+ end
62
87
  end
63
88
 
64
- attr_reader :node_provider
89
+ attr_reader :machine_spec
90
+
91
+ def machine_options
92
+ configs = []
93
+ configs << {
94
+ :convergence_options =>
95
+ [ :chef_server,
96
+ :allow_overwrite_keys,
97
+ :source_key, :source_key_path, :source_key_pass_phrase,
98
+ :private_key_options,
99
+ :ohai_hints,
100
+ :public_key_path, :public_key_format,
101
+ :admin, :validator
102
+ ].inject({}) do |result, key|
103
+ result[key] = new_resource.send(key)
104
+ result
105
+ end
106
+ }
107
+ configs << new_resource.machine_options if new_resource.machine_options
108
+ configs << new_driver_config[:machine_options] if new_driver_config[:machine_options]
109
+ Cheffish::MergedConfig.new(*configs)
110
+ end
65
111
 
66
112
  def load_current_resource
67
- @node_provider = Chef::Provider::ChefNode.new(new_resource, run_context)
68
- @node_provider.load_current_resource
113
+ node_driver = Chef::Provider::ChefNode.new(new_resource, run_context)
114
+ node_driver.load_current_resource
115
+ json = node_driver.new_json
116
+ json['normal']['metal'] = node_driver.current_json['normal']['metal']
117
+ @machine_spec = ChefMetal::ChefMachineSpec.new(json, new_resource.chef_server)
69
118
  end
70
119
 
71
120
  def self.upload_files(action_handler, machine, files)
@@ -87,6 +136,6 @@ class Chef::Provider::Machine < Chef::Provider::LWRPBase
87
136
  private
88
137
 
89
138
  def upload_files(machine)
90
- Machine.upload_files(self, machine, new_resource.files)
139
+ Machine.upload_files(action_handler, machine, new_resource.files)
91
140
  end
92
141
  end
@@ -1,12 +1,14 @@
1
1
  require 'chef/chef_fs/parallelizer'
2
2
  require 'chef/provider/lwrp_base'
3
3
  require 'chef/provider/machine'
4
- require 'chef_metal/provider_action_handler'
4
+ require 'chef_metal/chef_provider_action_handler'
5
5
  require 'chef_metal/add_prefix_action_handler'
6
6
 
7
7
  class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
8
8
 
9
- include ChefMetal::ProviderActionHandler
9
+ def action_handler
10
+ @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
11
+ end
10
12
 
11
13
  use_inline_resources
12
14
 
@@ -18,64 +20,59 @@ class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
18
20
  @parallelizer ||= Chef::ChefFS::Parallelizer.new(new_resource.max_simultaneous || 100)
19
21
  end
20
22
 
21
- action :boot do
22
- with_booted_machines
23
+ action :allocate do
24
+ by_new_driver.each do |driver, specs_and_options|
25
+ driver.allocate_machines(action_handler, specs_and_options, parallelizer) do |machine_spec|
26
+ machine_spec.save(action_handler)
27
+ end
28
+ end
29
+ end
30
+
31
+ action :ready do
32
+ with_ready_machines
23
33
  end
24
34
 
25
35
  action :setup do
26
- with_booted_machines do |machine|
27
- prefixed_handler = ChefMetal::AddPrefixActionHandler.new(self, "[#{machine[:resource].name}] ")
28
- machine[:machine].setup_convergence(prefixed_handler, machine[:resource])
29
- Chef::Provider::Machine.upload_files(prefixed_handler, machine[:machine], machine[:resource].files)
36
+ with_ready_machines do |m|
37
+ prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:resource].name}] ")
38
+ machine[:machine].setup_convergence(prefixed_handler)
39
+ Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:resource].files)
30
40
  end
31
41
  end
32
42
 
33
43
  action :converge do
34
- with_booted_machines do |machine|
35
- prefixed_handler = ChefMetal::AddPrefixActionHandler.new(self, "[#{machine[:resource].name}] ")
36
- machine[:machine].setup_convergence(prefixed_handler, machine[:resource])
37
- Chef::Provider::Machine.upload_files(prefixed_handler, machine[:machine], machine[:resource].files)
38
- machine[:machine].converge(prefixed_handler, machine[:resource].chef_server)
44
+ with_ready_machines do |m|
45
+ prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:resource].name}] ")
46
+ m[:machine].setup_convergence(prefixed_handler)
47
+ Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:resource].files)
48
+ m[:machine].converge(prefixed_handler)
39
49
  end
40
50
  end
41
51
 
42
52
  action :stop do
43
- parallel_do(@by_provisioner) do |provisioner, node_urls|
44
- provisioner.stop_machines(self, node_urls.map { |n| @by_node[n][:provider].node_provider.current_json }, parallelizer)
53
+ parallel_do(by_current_driver) do |driver, specs_and_options|
54
+ driver.stop_machines(action_handler, specs_and_options, parallelizer)
45
55
  end
46
56
  end
47
57
 
48
- action :delete do
49
- parallel_do(@by_provisioner) do |provisioner, node_urls|
50
- provisioner.delete_machines(self, node_urls.map { |n| @by_node[n][:provider].node_provider.current_json }, parallelizer)
58
+ action :destroy do
59
+ parallel_do(by_current_driver) do |driver, specs_and_options|
60
+ driver.destroy_machines(action_handler, specs_and_options, parallelizer)
51
61
  end
52
62
  end
53
63
 
54
- def with_booted_machines
55
- parallel_do(@by_provisioner) do |provisioner, node_urls|
56
- machines = node_urls.map do |node_url|
57
- # Fill in the provisioner options and output in case they got overwritten
58
- machine = @by_node[node_url]
59
- machine[:node] = machine[:provider].node_provider.new_json
60
- machine[:node]['normal']['provisioner_options'] = machine[:resource].provisioner_options
61
- machine[:node]['normal']['provisioner_output'] = machine[:provider].node_provider.current_json['normal']['provisioner_output']
62
- machine
63
- end
64
-
65
- # TODO I don't understand why the object_id hack was necessary. Using the
66
- # node as a key didn't work. If we could pass node_urls through acquire_machines,
67
- # that would solve the problem in a bestest way (nodes themselves are not
68
- # necessarily unique without knowing the chef_server with which they are
69
- # associated)
70
- by_node_json = machines.inject({}) { |result, machine| result[machine[:node].object_id] = machine; result }
71
- provisioner.acquire_machines(self, by_node_json.values.map { |m| m[:node] }, parallelizer) do |node_json, machine_obj|
72
- machine = by_node_json[node_json.object_id]
64
+ def with_ready_machines
65
+ action_allocate
66
+ by_id = @machines.inject({}) { |hash,m| hash[m[:spec].id] = m; hash }
67
+ parallel_do(by_new_driver) do |driver, specs_and_options|
68
+ driver.ready_machines(action_handler, specs_and_options, parallelizer) do |machine|
69
+ m = by_id[machine.machine_spec.id]
73
70
 
74
- machine[:machine] = machine_obj
71
+ m[:machine] = machine
75
72
  begin
76
- yield machine if block_given?
73
+ yield m if block_given?
77
74
  ensure
78
- machine_obj.disconnect
75
+ machine.disconnect
79
76
  end
80
77
  end
81
78
  end
@@ -88,29 +85,41 @@ class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
88
85
  parallelizer.parallelize(enum, options, &block).to_a
89
86
  end
90
87
 
91
- def node_url(machine_resource)
92
- "#{machine_resource.chef_server[:chef_server_url]}/nodes/#{machine_resource.name}"
88
+ def by_new_driver
89
+ result = {}
90
+ @machines.each do |m|
91
+ if m[:resource].driver
92
+ driver = run_context.chef_metal.driver_for(m[:resource].driver)
93
+ result[driver] ||= {}
94
+ result[driver][m[:spec]] = m[:options]
95
+ end
96
+ end
97
+ result
98
+ end
99
+
100
+ def by_current_driver
101
+ result = {}
102
+ @machines.each do |m|
103
+ if m[:spec].driver_url
104
+ driver = run_context.chef_metal.driver_for_url(m[:spec].driver_url)
105
+ result[driver] ||= {}
106
+ result[driver][m[:spec]] = m[:options]
107
+ end
108
+ end
109
+ result
93
110
  end
94
111
 
95
112
  def load_current_resource
96
- # Figure out which machines are in the batch, remove duplicates, and retrieve
97
- # the nodes from the Chef server if they exist.
98
- @by_provisioner = {}
99
- @by_node = {}
100
- new_resource.machines.each do |machine_resource|
101
- next if @by_node.has_key?(node_url(machine_resource))
102
- next unless Array(machine_resource.action).include?(:create)
103
- @by_node[node_url(machine_resource)] = {
113
+ # Load nodes in parallel
114
+ @machines = parallel_do(new_resource.machines) do |machine_resource|
115
+ provider = Chef::Provider::Machine.new(machine_resource, machine_resource.run_context)
116
+ provider.load_current_resource
117
+ {
104
118
  :resource => machine_resource,
105
- :provider => Chef::Provider::Machine.new(machine_resource, run_context)
119
+ :spec => provider.machine_spec,
120
+ :options => provider.machine_options
106
121
  }
107
- @by_provisioner[machine_resource.provisioner] ||= []
108
- @by_provisioner[machine_resource.provisioner] << node_url(machine_resource)
109
- end
110
- # Load nodes in parallel
111
- parallel_do(@by_node.values) do |machine|
112
- machine[:provider].load_current_resource
113
- end
122
+ end.to_a
114
123
  end
115
124
 
116
125
  end
@@ -1,10 +1,12 @@
1
1
  require 'chef/provider/lwrp_base'
2
- require 'cheffish/cheffish_server_api'
3
- require 'chef_metal/provider_action_handler'
2
+ require 'chef_metal/chef_provider_action_handler'
3
+ require 'chef_metal/machine'
4
4
 
5
5
  class Chef::Provider::MachineExecute < Chef::Provider::LWRPBase
6
6
 
7
- include ChefMetal::ProviderActionHandler
7
+ def action_handler
8
+ @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
9
+ end
8
10
 
9
11
  use_inline_resources
10
12
 
@@ -17,14 +19,12 @@ class Chef::Provider::MachineExecute < Chef::Provider::LWRPBase
17
19
  if new_resource.machine.kind_of?(ChefMetal::Machine)
18
20
  new_resource.machine
19
21
  else
20
- # TODO this is inefficient, can we cache or something?
21
- node = Cheffish::CheffishServerAPI.new(new_resource.chef_server).get("/nodes/#{new_resource.machine}")
22
- new_resource.provisioner.connect_to_machine(node)
22
+ run_context.chef_metal.connect_to_machine(new_resource.machine, new_resource.chef_server)
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
27
  action :run do
28
- machine.execute(self, new_resource.command)
28
+ machine.execute(action_handler, new_resource.command)
29
29
  end
30
30
  end