chef-metal 0.14.2 → 0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/README.md +2 -257
  4. data/Rakefile +0 -4
  5. data/lib/chef_metal.rb +1 -87
  6. data/lib/chef_metal/action_handler.rb +1 -66
  7. data/lib/chef_metal/add_prefix_action_handler.rb +1 -29
  8. data/lib/chef_metal/chef_image_spec.rb +1 -106
  9. data/lib/chef_metal/chef_machine_spec.rb +1 -82
  10. data/lib/chef_metal/chef_provider_action_handler.rb +1 -72
  11. data/lib/chef_metal/chef_run_data.rb +1 -125
  12. data/lib/chef_metal/convergence_strategy.rb +1 -26
  13. data/lib/chef_metal/convergence_strategy/install_cached.rb +1 -157
  14. data/lib/chef_metal/convergence_strategy/install_msi.rb +1 -56
  15. data/lib/chef_metal/convergence_strategy/install_sh.rb +1 -53
  16. data/lib/chef_metal/convergence_strategy/no_converge.rb +1 -37
  17. data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +1 -181
  18. data/lib/chef_metal/driver.rb +1 -288
  19. data/lib/chef_metal/image_spec.rb +1 -70
  20. data/lib/chef_metal/machine.rb +1 -110
  21. data/lib/chef_metal/machine/basic_machine.rb +1 -82
  22. data/lib/chef_metal/machine/unix_machine.rb +1 -276
  23. data/lib/chef_metal/machine/windows_machine.rb +1 -102
  24. data/lib/chef_metal/machine_spec.rb +1 -78
  25. data/lib/chef_metal/recipe_dsl.rb +1 -94
  26. data/lib/chef_metal/transport.rb +1 -87
  27. data/lib/chef_metal/transport/ssh.rb +1 -288
  28. data/lib/chef_metal/transport/winrm.rb +1 -134
  29. data/lib/chef_metal/version.rb +1 -3
  30. metadata +19 -145
  31. data/bin/metal +0 -275
  32. data/lib/chef/provider/machine.rb +0 -171
  33. data/lib/chef/provider/machine_batch.rb +0 -186
  34. data/lib/chef/provider/machine_execute.rb +0 -30
  35. data/lib/chef/provider/machine_file.rb +0 -49
  36. data/lib/chef/provider/machine_image.rb +0 -54
  37. data/lib/chef/resource/machine.rb +0 -116
  38. data/lib/chef/resource/machine_batch.rb +0 -72
  39. data/lib/chef/resource/machine_execute.rb +0 -22
  40. data/lib/chef/resource/machine_file.rb +0 -28
  41. data/lib/chef/resource/machine_image.rb +0 -29
@@ -1,171 +0,0 @@
1
- require 'chef/provider/lwrp_base'
2
- require 'chef/provider/chef_node'
3
- require 'openssl'
4
- require 'chef_metal/chef_provider_action_handler'
5
- require 'chef_metal/chef_machine_spec'
6
-
7
- class Chef::Provider::Machine < Chef::Provider::LWRPBase
8
-
9
- def action_handler
10
- @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
11
- end
12
-
13
- use_inline_resources
14
-
15
- def whyrun_supported?
16
- true
17
- end
18
-
19
- action :allocate do
20
- if current_driver && current_driver.driver_url != new_driver.driver_url
21
- raise "Cannot move '#{machine_spec.name}' from #{current_driver.driver_url} to #{new_driver.driver_url}: machine moving is not supported. Destroy and recreate."
22
- end
23
- if !new_driver
24
- raise "Driver not specified for machine #{machine_spec.name}"
25
- end
26
- new_driver.allocate_machine(action_handler, machine_spec, new_machine_options)
27
- machine_spec.save(action_handler)
28
- end
29
-
30
- action :ready do
31
- action_allocate
32
- machine = current_driver.ready_machine(action_handler, machine_spec, current_machine_options)
33
- machine_spec.save(action_handler)
34
- machine
35
- end
36
-
37
- action :setup do
38
- machine = action_ready
39
- begin
40
- machine.setup_convergence(action_handler)
41
- machine_spec.save(action_handler)
42
- upload_files(machine)
43
- ensure
44
- machine.disconnect
45
- end
46
- end
47
-
48
- action :converge do
49
- machine = action_ready
50
- begin
51
- machine.setup_convergence(action_handler)
52
- machine_spec.save(action_handler)
53
- upload_files(machine)
54
- # If we were asked to converge, or anything changed, or if a converge has never succeeded, converge.
55
- if new_resource.converge || (new_resource.converge.nil? && resource_updated?) ||
56
- !machine_spec.node['automatic'] || machine_spec.node['automatic'].size == 0
57
- machine.converge(action_handler)
58
- end
59
- ensure
60
- machine.disconnect
61
- end
62
- end
63
-
64
- action :converge_only do
65
- machine = run_context.chef_metal.connect_to_machine(machine_spec, current_machine_options)
66
- begin
67
- machine.converge(action_handler)
68
- ensure
69
- machine.disconnect
70
- end
71
- end
72
-
73
- action :stop do
74
- if current_driver
75
- current_driver.stop_machine(action_handler, machine_spec, current_machine_options)
76
- end
77
- end
78
-
79
- action :destroy do
80
- if current_driver
81
- current_driver.destroy_machine(action_handler, machine_spec, current_machine_options)
82
- end
83
- end
84
-
85
- attr_reader :machine_spec
86
-
87
- def new_driver
88
- run_context.chef_metal.driver_for(new_resource.driver)
89
- end
90
-
91
- def current_driver
92
- if machine_spec.driver_url
93
- run_context.chef_metal.driver_for(machine_spec.driver_url)
94
- end
95
- end
96
-
97
- def from_image_spec
98
- @from_image_spec ||= begin
99
- if new_resource.from_image
100
- ChefMetal::ChefImageSpec.get(new_resource.from_image, new_resource.chef_server)
101
- else
102
- nil
103
- end
104
- end
105
- end
106
-
107
- def new_machine_options
108
- machine_options(new_driver)
109
- end
110
-
111
- def current_machine_options
112
- machine_options(current_driver)
113
- end
114
-
115
- def machine_options(driver)
116
- configs = []
117
-
118
- if from_image_spec && from_image_spec.machine_options
119
- configs << from_image_spec.machine_options
120
- end
121
-
122
- configs << {
123
- :convergence_options =>
124
- [ :chef_server,
125
- :allow_overwrite_keys,
126
- :source_key, :source_key_path, :source_key_pass_phrase,
127
- :private_key_options,
128
- :ohai_hints,
129
- :public_key_path, :public_key_format,
130
- :admin, :validator
131
- ].inject({}) do |result, key|
132
- result[key] = new_resource.send(key)
133
- result
134
- end
135
- }
136
-
137
- configs << new_resource.machine_options if new_resource.machine_options
138
- configs << driver.config[:machine_options] if driver.config[:machine_options]
139
- Cheffish::MergedConfig.new(*configs)
140
- end
141
-
142
- def load_current_resource
143
- node_driver = Chef::Provider::ChefNode.new(new_resource, run_context)
144
- node_driver.load_current_resource
145
- json = node_driver.new_json
146
- json['normal']['metal'] = node_driver.current_json['normal']['metal']
147
- @machine_spec = ChefMetal::ChefMachineSpec.new(json, new_resource.chef_server)
148
- end
149
-
150
- def self.upload_files(action_handler, machine, files)
151
- if files
152
- files.each_pair do |remote_file, local|
153
- if local.is_a?(Hash)
154
- if local[:local_path]
155
- machine.upload_file(action_handler, local[:local_path], remote_file)
156
- else
157
- machine.write_file(action_handler, remote_file, local[:content])
158
- end
159
- else
160
- machine.upload_file(action_handler, local, remote_file)
161
- end
162
- end
163
- end
164
- end
165
-
166
- private
167
-
168
- def upload_files(machine)
169
- Machine.upload_files(action_handler, machine, new_resource.files)
170
- end
171
- end
@@ -1,186 +0,0 @@
1
- require 'chef/chef_fs/parallelizer'
2
- require 'chef/provider/lwrp_base'
3
- require 'chef/provider/machine'
4
- require 'chef_metal/chef_provider_action_handler'
5
- require 'chef_metal/add_prefix_action_handler'
6
- require 'chef_metal/machine_spec'
7
- require 'chef_metal/chef_machine_spec'
8
-
9
- class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
10
-
11
- def action_handler
12
- @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
13
- end
14
-
15
- use_inline_resources
16
-
17
- def whyrun_supported?
18
- true
19
- end
20
-
21
- def parallelizer
22
- @parallelizer ||= Chef::ChefFS::Parallelizer.new(new_resource.max_simultaneous || 100)
23
- end
24
-
25
- action :allocate do
26
- by_new_driver.each do |driver, specs_and_options|
27
- driver.allocate_machines(action_handler, specs_and_options, parallelizer) do |machine_spec|
28
- prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{machine_spec.name}] ")
29
- machine_spec.save(prefixed_handler)
30
- end
31
- end
32
- end
33
-
34
- action :ready do
35
- with_ready_machines
36
- end
37
-
38
- action :setup do
39
- with_ready_machines do |m|
40
- prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:spec].name}] ")
41
- m[:machine].setup_convergence(prefixed_handler)
42
- m[:spec].save(prefixed_handler)
43
- Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:files])
44
- end
45
- end
46
-
47
- action :converge do
48
- with_ready_machines do |m|
49
- prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:spec].name}] ")
50
- m[:machine].setup_convergence(prefixed_handler)
51
- m[:spec].save(action_handler)
52
- Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:files])
53
- # TODO only converge if machine was modified
54
- m[:machine].converge(prefixed_handler)
55
- m[:spec].save(prefixed_handler)
56
- end
57
- end
58
-
59
- action :converge_only do
60
- parallel_do(@machines) do |m|
61
- prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:spec].name}] ")
62
- machine = run_context.chef_metal.connect_to_machine(m[:spec])
63
- machine.converge(prefixed_handler)
64
- end
65
- end
66
-
67
- action :destroy do
68
- parallel_do(by_current_driver) do |driver, specs_and_options|
69
- driver.destroy_machines(action_handler, specs_and_options, parallelizer)
70
- end
71
- end
72
-
73
- action :stop do
74
- parallel_do(by_current_driver) do |driver, specs_and_options|
75
- driver.stop_machines(action_handler, specs_and_options, parallelizer)
76
- end
77
- end
78
-
79
- def with_ready_machines
80
- action_allocate
81
- by_id = @machines.inject({}) { |hash,m| hash[m[:spec].id] = m; hash }
82
- parallel_do(by_new_driver) do |driver, specs_and_options|
83
- driver.ready_machines(action_handler, specs_and_options, parallelizer) do |machine|
84
- machine.machine_spec.save(action_handler)
85
-
86
- m = by_id[machine.machine_spec.id]
87
-
88
- m[:machine] = machine
89
- begin
90
- yield m if block_given?
91
- ensure
92
- machine.disconnect
93
- end
94
- end
95
- end
96
- end
97
-
98
- # TODO in many of these cases, the order of the results only matters because you
99
- # want to match it up with the input. Make a parallelize method that doesn't
100
- # care about order and spits back results as quickly as possible.
101
- def parallel_do(enum, options = {}, &block)
102
- parallelizer.parallelize(enum, options, &block).to_a
103
- end
104
-
105
- def by_new_driver
106
- result = {}
107
- drivers = {}
108
- @machines.each do |m|
109
- if m[:desired_driver]
110
- drivers[m[:desired_driver]] ||= run_context.chef_metal.driver_for(m[:desired_driver])
111
- driver = drivers[m[:desired_driver]]
112
- # Check whether the current driver is same or different; we disallow
113
- # moving a machine from one place to another.
114
- if m[:spec].driver_url
115
- drivers[m[:spec].driver_url] ||= run_context.chef_metal.driver_for(m[:spec].driver_url)
116
- current_driver = drivers[m[:spec].driver_url]
117
- if driver.driver_url != current_driver.driver_url
118
- raise "Cannot move '#{m[:spec].name}' from #{current_driver.driver_url} to #{driver.driver_url}: machine moving is not supported. Destroy and recreate."
119
- end
120
- end
121
- result[driver] ||= {}
122
- result[driver][m[:spec]] = m[:machine_options].call(driver)
123
- else
124
- raise "No driver specified for #{m[:spec].name}"
125
- end
126
- end
127
- result
128
- end
129
-
130
- def by_current_driver
131
- result = {}
132
- drivers = {}
133
- @machines.each do |m|
134
- if m[:spec].driver_url
135
- drivers[m[:spec].driver_url] ||= run_context.chef_metal.driver_for(m[:spec].driver_url)
136
- driver = drivers[m[:spec].driver_url]
137
- result[driver] ||= {}
138
- result[driver][m[:spec]] = m[:machine_options].call(driver)
139
- end
140
- end
141
- result
142
- end
143
-
144
- def load_current_resource
145
- # Load nodes in parallel
146
- @machines = parallel_do(new_resource.machines) do |machine|
147
- if machine.is_a?(Chef::Resource::Machine)
148
- machine_resource = machine
149
- provider = Chef::Provider::Machine.new(machine_resource, machine_resource.run_context)
150
- provider.load_current_resource
151
- {
152
- :spec => provider.machine_spec,
153
- :desired_driver => machine_resource.driver,
154
- :files => machine_resource.files,
155
- :machine_options => proc { |driver| provider.machine_options(driver) }
156
- }
157
- elsif machine.is_a?(ChefMetal::MachineSpec)
158
- machine_spec = machine
159
- {
160
- :spec => machine_spec,
161
- :desired_driver => new_resource.driver,
162
- :files => new_resource.files,
163
- :machine_options => proc { |driver| machine_options(driver) }
164
- }
165
- else
166
- name = machine
167
- machine_spec = ChefMetal::ChefMachineSpec.get(name, new_resource.chef_server) ||
168
- ChefMetal::ChefMachineSpec.empty(name, new_resource.chef_server)
169
- {
170
- :spec => machine_spec,
171
- :desired_driver => new_resource.driver,
172
- :files => new_resource.files,
173
- :machine_options => proc { |driver| machine_options(driver) }
174
- }
175
- end
176
- end.to_a
177
- end
178
-
179
- def machine_options(driver)
180
- result = { :convergence_options => { :chef_server => new_resource.chef_server } }
181
- result = Chef::Mixin::DeepMerge.hash_only_merge(result, run_context.chef_metal.config[:machine_options]) if run_context.chef_metal.config[:machine_options]
182
- result = Chef::Mixin::DeepMerge.hash_only_merge(result, driver.config[:machine_options]) if driver.config && driver.config[:machine_options]
183
- result = Chef::Mixin::DeepMerge.hash_only_merge(result, new_resource.machine_options)
184
- result
185
- end
186
- end
@@ -1,30 +0,0 @@
1
- require 'chef/provider/lwrp_base'
2
- require 'chef_metal/chef_provider_action_handler'
3
- require 'chef_metal/machine'
4
-
5
- class Chef::Provider::MachineExecute < Chef::Provider::LWRPBase
6
-
7
- def action_handler
8
- @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
9
- end
10
-
11
- use_inline_resources
12
-
13
- def whyrun_supported?
14
- true
15
- end
16
-
17
- def machine
18
- @machine ||= begin
19
- if new_resource.machine.kind_of?(ChefMetal::Machine)
20
- new_resource.machine
21
- else
22
- run_context.chef_metal.connect_to_machine(new_resource.machine, new_resource.chef_server)
23
- end
24
- end
25
- end
26
-
27
- action :run do
28
- machine.execute(action_handler, new_resource.command)
29
- end
30
- end
@@ -1,49 +0,0 @@
1
- require 'chef/provider/lwrp_base'
2
- require 'chef_metal/chef_provider_action_handler'
3
- require 'chef_metal/machine'
4
-
5
- class Chef::Provider::MachineFile < Chef::Provider::LWRPBase
6
-
7
- def action_handler
8
- @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
9
- end
10
-
11
- use_inline_resources
12
-
13
- def whyrun_supported?
14
- true
15
- end
16
-
17
- def machine
18
- @machine ||= begin
19
- if new_resource.machine.kind_of?(ChefMetal::Machine)
20
- new_resource.machine
21
- else
22
- run_context.chef_metal.connect_to_machine(new_resource.machine, new_resource.chef_server)
23
- end
24
- end
25
- end
26
-
27
- action :upload do
28
- if new_resource.content
29
- machine.write_file(action_handler, new_resource.path, new_resource.content)
30
- else
31
- machine.upload_file(action_handler, new_resource.local_path, new_resource.path)
32
- end
33
-
34
- attributes = {}
35
- attributes[:group] = new_resource.group if new_resource.group
36
- attributes[:owner] = new_resource.owner if new_resource.owner
37
- attributes[:mode] = new_resource.mode if new_resource.mode
38
-
39
- machine.set_attributes(action_handler, new_resource.path, attributes)
40
- end
41
-
42
- action :download do
43
- machine.download_file(action_handler, new_resource.path, new_resource.local_path)
44
- end
45
-
46
- action :delete do
47
- machine.delete_file(action_handler, new_resource.path)
48
- end
49
- end
@@ -1,54 +0,0 @@
1
- require 'chef/provider/lwrp_base'
2
- require 'chef/provider/chef_node'
3
- require 'openssl'
4
- require 'chef_metal/chef_provider_action_handler'
5
- require 'chef_metal/chef_image_spec'
6
-
7
- class Chef::Provider::MachineImage < Chef::Provider::LWRPBase
8
- def action_handler
9
- @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
10
- end
11
-
12
- def load_current_resource
13
- end
14
-
15
- # Get the driver specified in the resource
16
- def new_driver
17
- @new_driver ||= run_context.chef_metal.driver_for(new_resource.driver)
18
- end
19
-
20
- action :create do
21
- # Get the image mapping on the server (from name to image-id)
22
- image_spec = ChefMetal::ChefImageSpec.get(new_resource.name, new_resource.chef_server) ||
23
- ChefMetal::ChefImageSpec.empty(new_resource.name, new_resource.chef_server)
24
- if image_spec.location
25
- # TODO check for real existence and maybe update
26
- else
27
- #
28
- # Create a new image
29
- #
30
- image_spec.machine_options = new_resource.machine_options
31
- create_image(image_spec)
32
- end
33
- end
34
-
35
- action :destroy do
36
- end
37
-
38
- def create_image(image_spec)
39
- # 1. Create the exemplar machine
40
- machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
41
- machine_provider.load_current_resource
42
- machine_provider.action_converge
43
-
44
- # 2. Create the image
45
- new_driver.allocate_image(action_handler, image_spec, new_resource.image_options,
46
- machine_provider.machine_spec)
47
-
48
- # 3. Save the linkage from name -> image id
49
- image_spec.save(action_handler)
50
-
51
- # 4. Wait for image to be ready
52
- new_driver.ready_image(action_handler, image_spec, new_resource.image_options)
53
- end
54
- end