clc-fork-chef-metal 0.11.beta.5 → 0.11.beta.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/chef/provider/machine_batch.rb +62 -18
- data/lib/chef/resource/machine.rb +2 -4
- data/lib/chef/resource/machine_batch.rb +27 -3
- data/lib/chef_metal/chef_machine_spec.rb +16 -2
- data/lib/chef_metal/chef_run_data.rb +13 -4
- data/lib/chef_metal/recipe_dsl.rb +67 -24
- data/lib/chef_metal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef0925df69f5f0d7cf6f51b0b849f155d4c2b6ee
|
4
|
+
data.tar.gz: dfc2e5acb07a424fac4d9041dff233c631aaf111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbbc0262f139ba2883711e183cb192f895b3accd2389c56a8b68619b21c85fcbcecbd6cbf134b1b45352729334f6bc5e7a34ff759430fc1eadf6e8fe81dfcd04
|
7
|
+
data.tar.gz: 7b3e07b27e49b7962d1f20a7ef6e7823d70d78b5606022fcac731f53a1c8f6808f9b017a975ed4bd811cfe70fabda92f423b7158aa67099bb0da2f3f3332d2bf
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Chef Metal Changelog
|
2
2
|
|
3
|
+
## 0.11.beta.6 (5/28/2014)
|
4
|
+
|
5
|
+
- Fix machine_batch defaults to be significantly less stupid
|
6
|
+
- Remove with_machine_batch
|
7
|
+
- Allow this:
|
8
|
+
```ruby
|
9
|
+
machine_batch do
|
10
|
+
machine 'a'
|
11
|
+
machine 'b'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
- Allow this:
|
15
|
+
```ruby
|
16
|
+
machine_batch do
|
17
|
+
machines 'a', 'b', 'c'
|
18
|
+
action :destroy
|
19
|
+
end
|
20
|
+
- fix SSH gateway code to honor any options given (@marcusn)
|
21
|
+
|
3
22
|
## 0.11.beta.5 (5/28/2014)
|
4
23
|
|
5
24
|
- fix issue setting Hosted Chef ACLs on nodes
|
@@ -3,6 +3,8 @@ require 'chef/provider/lwrp_base'
|
|
3
3
|
require 'chef/provider/machine'
|
4
4
|
require 'chef_metal/chef_provider_action_handler'
|
5
5
|
require 'chef_metal/add_prefix_action_handler'
|
6
|
+
require 'chef_metal/machine_spec'
|
7
|
+
require 'chef_metal/chef_machine_spec'
|
6
8
|
|
7
9
|
class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
|
8
10
|
|
@@ -34,27 +36,28 @@ class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
|
|
34
36
|
|
35
37
|
action :setup do
|
36
38
|
with_ready_machines do |m|
|
37
|
-
prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:
|
39
|
+
prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:spec].name}] ")
|
38
40
|
machine[:machine].setup_convergence(prefixed_handler)
|
39
41
|
m[:spec].save(action_handler)
|
40
|
-
Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:
|
42
|
+
Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:files])
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
action :converge do
|
45
47
|
with_ready_machines do |m|
|
46
|
-
prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:
|
48
|
+
prefixed_handler = ChefMetal::AddPrefixActionHandler.new(action_handler, "[#{m[:spec].name}] ")
|
47
49
|
m[:machine].setup_convergence(prefixed_handler)
|
48
50
|
m[:spec].save(action_handler)
|
49
|
-
Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:
|
51
|
+
Chef::Provider::Machine.upload_files(prefixed_handler, m[:machine], m[:files])
|
50
52
|
m[:machine].converge(prefixed_handler)
|
51
53
|
m[:spec].save(action_handler)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
action :
|
56
|
-
parallel_do(
|
57
|
-
|
57
|
+
action :converge_only do
|
58
|
+
parallel_do(@machines) do |m|
|
59
|
+
machine = run_context.chef_metal.connect_to_machine(m[:spec])
|
60
|
+
machine.converge(action_handler)
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
@@ -64,6 +67,12 @@ class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
|
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
70
|
+
action :stop do
|
71
|
+
parallel_do(by_current_driver) do |driver, specs_and_options|
|
72
|
+
driver.stop_machines(action_handler, specs_and_options, parallelizer)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
67
76
|
def with_ready_machines
|
68
77
|
action_allocate
|
69
78
|
by_id = @machines.inject({}) { |hash,m| hash[m[:spec].id] = m; hash }
|
@@ -93,8 +102,8 @@ class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
|
|
93
102
|
def by_new_driver
|
94
103
|
result = {}
|
95
104
|
@machines.each do |m|
|
96
|
-
if m[:
|
97
|
-
driver = run_context.chef_metal.driver_for(m[:
|
105
|
+
if m[:desired_driver]
|
106
|
+
driver = run_context.chef_metal.driver_for(m[:desired_driver])
|
98
107
|
result[driver] ||= {}
|
99
108
|
result[driver][m[:spec]] = m[:options]
|
100
109
|
end
|
@@ -116,15 +125,50 @@ class Chef::Provider::MachineBatch < Chef::Provider::LWRPBase
|
|
116
125
|
|
117
126
|
def load_current_resource
|
118
127
|
# Load nodes in parallel
|
119
|
-
@machines = parallel_do(new_resource.machines) do |
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
+
@machines = parallel_do(new_resource.machines) do |machine|
|
129
|
+
if machine.is_a?(Chef::Resource::Machine)
|
130
|
+
machine_resource = machine
|
131
|
+
provider = Chef::Provider::Machine.new(machine_resource, machine_resource.run_context)
|
132
|
+
provider.load_current_resource
|
133
|
+
{
|
134
|
+
:spec => provider.machine_spec,
|
135
|
+
:desired_driver => machine_resource.driver,
|
136
|
+
:files => machine_resource.files,
|
137
|
+
:options => provider.machine_options
|
138
|
+
}
|
139
|
+
elsif machine.is_a?(ChefMetal::MachineSpec)
|
140
|
+
machine_spec = machine
|
141
|
+
{
|
142
|
+
:spec => machine_spec,
|
143
|
+
:desired_driver => new_resource.driver,
|
144
|
+
:files => new_resource.files,
|
145
|
+
:options => new_machine_options
|
146
|
+
}
|
147
|
+
else
|
148
|
+
name = machine
|
149
|
+
machine_spec = ChefMetal::ChefMachineSpec.get(name, new_resource.chef_server) ||
|
150
|
+
ChefMetal::ChefMachineSpec.empty(name, new_resource.chef_server)
|
151
|
+
{
|
152
|
+
:spec => machine_spec,
|
153
|
+
:desired_driver => new_resource.driver,
|
154
|
+
:files => new_resource.files,
|
155
|
+
:options => new_machine_options
|
156
|
+
}
|
157
|
+
end
|
158
|
+
end.select { |m| !m.nil? }.to_a
|
159
|
+
end
|
160
|
+
|
161
|
+
def new_machine_options
|
162
|
+
@new_machine_options ||= begin
|
163
|
+
result = { :convergence_options => { :chef_server => new_resource.chef_server } }
|
164
|
+
result = Chef::Mixin::DeepMerge.hash_only_merge(result, new_config[:machine_options]) if new_config[:machine_options]
|
165
|
+
result = Chef::Mixin::DeepMerge.hash_only_merge(result, new_resource.machine_options)
|
166
|
+
result
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def new_config
|
171
|
+
@new_config ||= run_context.chef_metal.driver_config_for(new_resource.driver)
|
128
172
|
end
|
129
173
|
|
130
174
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'chef/resource/lwrp_base'
|
2
2
|
require 'cheffish'
|
3
3
|
require 'chef_metal'
|
4
|
+
require 'cheffish/merged_config'
|
4
5
|
|
5
6
|
class Chef::Resource::Machine < Chef::Resource::LWRPBase
|
6
7
|
self.resource_name = 'machine'
|
@@ -11,9 +12,6 @@ class Chef::Resource::Machine < Chef::Resource::LWRPBase
|
|
11
12
|
@chef_server = run_context.cheffish.current_chef_server
|
12
13
|
@driver = run_context.chef_metal.current_driver
|
13
14
|
@machine_options = run_context.chef_metal.current_machine_options
|
14
|
-
if run_context.chef_metal.current_machine_batch
|
15
|
-
run_context.chef_metal.current_machine_batch.machines << self
|
16
|
-
end
|
17
15
|
end
|
18
16
|
|
19
17
|
actions :allocate, :ready, :setup, :converge, :converge_only, :destroy, :stop
|
@@ -85,7 +83,7 @@ class Chef::Resource::Machine < Chef::Resource::LWRPBase
|
|
85
83
|
end
|
86
84
|
|
87
85
|
def add_machine_options(options)
|
88
|
-
@machine_options =
|
86
|
+
@machine_options = Cheffish::MergedConfig.new(options, @machine_options)
|
89
87
|
end
|
90
88
|
|
91
89
|
# chef client version and omnibus
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'chef/resource/lwrp_base'
|
2
|
+
require 'chef/mixin/deep_merge'
|
2
3
|
|
3
4
|
class Chef::Resource::MachineBatch < Chef::Resource::LWRPBase
|
4
5
|
self.resource_name = 'machine_batch'
|
@@ -6,15 +7,38 @@ class Chef::Resource::MachineBatch < Chef::Resource::LWRPBase
|
|
6
7
|
def initialize(*args)
|
7
8
|
super
|
8
9
|
@machines = []
|
10
|
+
@driver = run_context.chef_metal.current_driver
|
9
11
|
@chef_server = run_context.cheffish.current_chef_server
|
12
|
+
@machine_options = run_context.chef_metal.current_machine_options
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
# waits for that to complete, save the nodes, and THEN converges.
|
14
|
-
actions :acquire, :setup, :converge, :stop, :destroy
|
15
|
+
actions :allocate, :ready, :setup, :converge, :converge_only, :destroy, :stop
|
15
16
|
default_action :converge
|
16
17
|
|
17
18
|
attribute :machines, :kind_of => [ Array ]
|
18
19
|
attribute :max_simultaneous, :kind_of => [ Integer ]
|
20
|
+
attribute :from_recipe
|
21
|
+
|
22
|
+
# These four attributes are for when you pass names or MachineSpecs to
|
23
|
+
# "machines". Not used for auto-batch or explicit inline machine declarations.
|
24
|
+
attribute :driver
|
19
25
|
attribute :chef_server
|
26
|
+
attribute :machine_options
|
27
|
+
attribute :files, :kind_of => [ Array ]
|
28
|
+
|
29
|
+
def machines(*values)
|
30
|
+
if values.size == 0
|
31
|
+
@machines
|
32
|
+
else
|
33
|
+
@machines += values.flatten
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def machine(name, &block)
|
38
|
+
machines << from_recipe.build_resource(:machine, name, caller[0], &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_machine_options(options)
|
42
|
+
@machine_options = Chef::Mixin::DeepMerge.hash_only_merge(@machine_options, options)
|
43
|
+
end
|
20
44
|
end
|
@@ -14,11 +14,25 @@ module ChefMetal
|
|
14
14
|
end
|
15
15
|
|
16
16
|
#
|
17
|
-
# Get a MachineSpec from the chef server.
|
17
|
+
# Get a MachineSpec from the chef server. If the node does not exist on the
|
18
|
+
# server, it returns nil.
|
18
19
|
#
|
19
20
|
def self.get(name, chef_server = Cheffish.default_chef_server)
|
20
21
|
chef_api = Cheffish.chef_server_api(chef_server)
|
21
|
-
|
22
|
+
begin
|
23
|
+
ChefMachineSpec.new(chef_api.get("/nodes/#{name}"), chef_server)
|
24
|
+
rescue Net::HTTPServerException => e
|
25
|
+
if e.response.code == '404'
|
26
|
+
nil
|
27
|
+
else
|
28
|
+
raise
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Creates a new empty MachineSpec with the given name.
|
34
|
+
def self.empty(name, chef_server = Cheffish.default_chef_server)
|
35
|
+
ChefMachineSpec.new({ 'name' => name, 'normal' => {} }, chef_server)
|
22
36
|
end
|
23
37
|
|
24
38
|
#
|
@@ -16,7 +16,18 @@ module ChefMetal
|
|
16
16
|
|
17
17
|
with :driver
|
18
18
|
with :machine_options
|
19
|
-
|
19
|
+
|
20
|
+
def auto_batch_machines
|
21
|
+
if !@auto_batch_machines.nil?
|
22
|
+
@auto_batch_machines
|
23
|
+
else
|
24
|
+
config[:auto_batch_machines]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def auto_batch_machines=(value)
|
29
|
+
@auto_batch_machines = value
|
30
|
+
end
|
20
31
|
|
21
32
|
def current_driver
|
22
33
|
@current_driver || config[:driver]
|
@@ -25,10 +36,8 @@ module ChefMetal
|
|
25
36
|
def current_machine_options
|
26
37
|
if @current_machine_options
|
27
38
|
@current_machine_options
|
28
|
-
elsif config[:drivers] && driver_for(current_driver) && config[:drivers][driver_for(current_driver).driver_url]
|
29
|
-
Cheffish::MergedConfig.new(config[:drivers][driver_for(current_driver).driver_url], config)[:machine_options] || {}
|
30
39
|
else
|
31
|
-
|
40
|
+
driver_config_for(current_driver)[:machine_options] || {}
|
32
41
|
end
|
33
42
|
end
|
34
43
|
|
@@ -14,33 +14,13 @@ class Chef
|
|
14
14
|
module DSL
|
15
15
|
module Recipe
|
16
16
|
def with_driver(driver, &block)
|
17
|
-
|
18
|
-
run_context.chef_metal.with_driver(driver, &block)
|
19
|
-
elsif driver.is_a?(ChefMetal::Driver)
|
20
|
-
run_context.chef_metal.with_driver(run_context.chef_metal.driver_for_url(driver), &block)
|
21
|
-
else
|
22
|
-
raise "with_driver accepts either a driver URL string or a ChefMetal::Driver instance. You tried passing a #{driver.class}."
|
23
|
-
end
|
17
|
+
run_context.chef_metal.with_driver(driver, &block)
|
24
18
|
end
|
25
19
|
|
26
20
|
def with_machine_options(machine_options, &block)
|
27
21
|
run_context.chef_metal.with_machine_options(machine_options, &block)
|
28
22
|
end
|
29
23
|
|
30
|
-
def with_machine_batch(the_machine_batch, options = {}, &block)
|
31
|
-
if the_machine_batch.is_a?(String)
|
32
|
-
the_machine_batch = machine_batch the_machine_batch do
|
33
|
-
if options[:action]
|
34
|
-
action options[:action]
|
35
|
-
end
|
36
|
-
if options[:max_simultaneous]
|
37
|
-
max_simultaneous options[:max_simultaneous]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
run_context.chef_metal.with_machine_batch(the_machine_batch, &block)
|
42
|
-
end
|
43
|
-
|
44
24
|
def current_machine_options
|
45
25
|
run_context.chef_metal.current_machine_options
|
46
26
|
end
|
@@ -49,19 +29,76 @@ class Chef
|
|
49
29
|
run_context.chef_metal.add_machine_options(options, &block)
|
50
30
|
end
|
51
31
|
|
32
|
+
NOT_PASSED = Object.new
|
33
|
+
|
34
|
+
def auto_batch_machines(value = NOT_PASSED)
|
35
|
+
if value == NOT_PASSED
|
36
|
+
run_context.chef_metal.auto_batch_machines
|
37
|
+
else
|
38
|
+
run_context.chef_metal.auto_batch_machines = value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def machine_batch_default_name
|
43
|
+
if @machine_batch_index
|
44
|
+
@machine_batch_index += 1
|
45
|
+
"default#{@machine_batch_index}"
|
46
|
+
else
|
47
|
+
@machine_batch_index = 0
|
48
|
+
"default"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def machine_batch(name = nil, &block)
|
53
|
+
name ||= machine_batch_default_name
|
54
|
+
recipe = self
|
55
|
+
declare_resource(:machine_batch, name, caller[0]) do
|
56
|
+
from_recipe recipe
|
57
|
+
instance_eval(&block)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
52
61
|
# When the machine resource is first declared, create a machine_batch (if there
|
53
62
|
# isn't one already)
|
54
63
|
def machine(name, &block)
|
55
|
-
|
56
|
-
|
64
|
+
resource = build_resource(:machine, name, caller[0], &block)
|
65
|
+
|
66
|
+
# Grab the previous resource so we can decide whether to batch this or make it its own resource.
|
67
|
+
previous_index = run_context.resource_collection.previous_index
|
68
|
+
previous = previous_index >= 0 ? run_context.resource_collection[previous_index] : nil
|
69
|
+
if run_context.chef_metal.auto_batch_machines &&
|
70
|
+
previous &&
|
71
|
+
Array(resource.action).size == 1 &&
|
72
|
+
Array(previous.action) == Array(resource.action)
|
73
|
+
|
74
|
+
# Handle batching similar machines (with similar actions)
|
75
|
+
if previous.is_a?(Chef::Resource::MachineBatch)
|
76
|
+
# If we see a machine declared after a previous machine_batch with the same action, add it to the batch.
|
77
|
+
previous.machines << resource
|
78
|
+
elsif previous.is_a?(Chef::Resource::Machine)
|
79
|
+
# If we see two machines in a row with the same action, batch them.
|
80
|
+
_self = self
|
81
|
+
batch = build_resource(:machine_batch, machine_batch_default_name) do
|
82
|
+
action resource.action
|
83
|
+
machines [ previous, resource ]
|
84
|
+
end
|
85
|
+
batch.from_recipe self
|
86
|
+
run_context.resource_collection[previous_index] = batch
|
87
|
+
else
|
88
|
+
run_context.resource_collection.insert(resource)
|
89
|
+
end
|
90
|
+
|
91
|
+
else
|
92
|
+
run_context.resource_collection.insert(resource)
|
57
93
|
end
|
58
|
-
|
94
|
+
resource
|
59
95
|
end
|
60
96
|
end
|
61
97
|
end
|
62
98
|
|
63
99
|
class Config
|
64
100
|
default(:driver) { ENV['CHEF_DRIVER'] }
|
101
|
+
default(:auto_batch_machines) { true }
|
65
102
|
# config_context :drivers do
|
66
103
|
# # each key is a driver_url, and each value can have driver, driver_options and machine_options
|
67
104
|
# config_strict_mode false
|
@@ -81,4 +118,10 @@ class Chef
|
|
81
118
|
@chef_metal ||= ChefMetal::ChefRunData.new(config)
|
82
119
|
end
|
83
120
|
end
|
121
|
+
|
122
|
+
class ResourceCollection
|
123
|
+
def previous_index
|
124
|
+
@insert_after_idx ? @insert_after_idx : @resources.length - 1
|
125
|
+
end
|
126
|
+
end
|
84
127
|
end
|
data/lib/chef_metal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clc-fork-chef-metal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.beta.
|
4
|
+
version: 0.11.beta.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wrock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|