chef-provisioning 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +899 -885
- data/Gemfile +17 -17
- data/LICENSE +201 -201
- data/README.md +312 -312
- data/Rakefile +55 -55
- data/chef-provisioning.gemspec +38 -38
- data/lib/chef/provider/load_balancer.rb +75 -75
- data/lib/chef/provider/machine.rb +219 -219
- data/lib/chef/provider/machine_batch.rb +224 -224
- data/lib/chef/provider/machine_execute.rb +36 -35
- data/lib/chef/provider/machine_file.rb +55 -55
- data/lib/chef/provider/machine_image.rb +105 -105
- data/lib/chef/provisioning.rb +110 -110
- data/lib/chef/provisioning/action_handler.rb +68 -68
- data/lib/chef/provisioning/add_prefix_action_handler.rb +35 -35
- data/lib/chef/provisioning/chef_managed_entry_store.rb +128 -128
- data/lib/chef/provisioning/chef_provider_action_handler.rb +74 -74
- data/lib/chef/provisioning/chef_run_data.rb +132 -132
- data/lib/chef/provisioning/convergence_strategy.rb +28 -28
- data/lib/chef/provisioning/convergence_strategy/ignore_convergence_failure.rb +54 -54
- data/lib/chef/provisioning/convergence_strategy/install_cached.rb +188 -188
- data/lib/chef/provisioning/convergence_strategy/install_msi.rb +71 -71
- data/lib/chef/provisioning/convergence_strategy/install_sh.rb +71 -71
- data/lib/chef/provisioning/convergence_strategy/no_converge.rb +35 -35
- data/lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb +255 -255
- data/lib/chef/provisioning/driver.rb +323 -323
- data/lib/chef/provisioning/load_balancer_spec.rb +14 -14
- data/lib/chef/provisioning/machine.rb +112 -112
- data/lib/chef/provisioning/machine/basic_machine.rb +84 -84
- data/lib/chef/provisioning/machine/unix_machine.rb +288 -288
- data/lib/chef/provisioning/machine/windows_machine.rb +108 -108
- data/lib/chef/provisioning/machine_image_spec.rb +34 -34
- data/lib/chef/provisioning/machine_spec.rb +58 -58
- data/lib/chef/provisioning/managed_entry.rb +121 -121
- data/lib/chef/provisioning/managed_entry_store.rb +136 -136
- data/lib/chef/provisioning/recipe_dsl.rb +99 -99
- data/lib/chef/provisioning/rspec.rb +27 -27
- data/lib/chef/provisioning/transport.rb +100 -100
- data/lib/chef/provisioning/transport/ssh.rb +403 -403
- data/lib/chef/provisioning/transport/winrm.rb +144 -156
- data/lib/chef/provisioning/version.rb +5 -5
- data/lib/chef/resource/chef_data_bag_resource.rb +146 -146
- data/lib/chef/resource/load_balancer.rb +57 -57
- data/lib/chef/resource/machine.rb +128 -128
- data/lib/chef/resource/machine_batch.rb +78 -78
- data/lib/chef/resource/machine_execute.rb +30 -29
- data/lib/chef/resource/machine_file.rb +34 -34
- data/lib/chef/resource/machine_image.rb +35 -35
- data/lib/chef_metal.rb +1 -1
- data/spec/chef/provisioning/convergence_strategy/ignore_convergence_failure_spec.rb +86 -86
- data/spec/spec_helper.rb +27 -27
- metadata +5 -5
@@ -1,57 +1,57 @@
|
|
1
|
-
require 'chef/resource/lwrp_base'
|
2
|
-
require 'cheffish'
|
3
|
-
require 'chef_metal'
|
4
|
-
require 'cheffish/merged_config'
|
5
|
-
|
6
|
-
class Chef
|
7
|
-
class Resource
|
8
|
-
class LoadBalancer < Chef::Resource::LWRPBase
|
9
|
-
|
10
|
-
self.resource_name = 'load_balancer'
|
11
|
-
|
12
|
-
def initialize(*args)
|
13
|
-
super
|
14
|
-
@chef_environment = run_context.cheffish.current_environment
|
15
|
-
@chef_server = run_context.cheffish.current_chef_server
|
16
|
-
@driver = run_context.chef_metal.current_driver
|
17
|
-
@load_balancer_options = run_context.chef_metal.current_load_balancer_options
|
18
|
-
end
|
19
|
-
|
20
|
-
actions :create, :destroy
|
21
|
-
default_action :create
|
22
|
-
|
23
|
-
# Driver attributes
|
24
|
-
attribute :driver
|
25
|
-
attribute :chef_server
|
26
|
-
attribute :load_balancer_options
|
27
|
-
attribute :name, :kind_of => String, :name_attribute => true
|
28
|
-
attribute :machines
|
29
|
-
|
30
|
-
def add_load_balancer_options(options)
|
31
|
-
@load_balancer_options = Cheffish::MergedConfig.new(options, @load_balancer_options)
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
# This is here because metal users will probably want to do things like:
|
36
|
-
# machine "foo"
|
37
|
-
# action :destroy
|
38
|
-
# end
|
39
|
-
#
|
40
|
-
# with_load_balancer_options :bootstrap_options => {...}
|
41
|
-
# machine "foo"
|
42
|
-
# converge true
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# Without this, the first resource's machine options will obliterate the second
|
46
|
-
# resource's machine options, and then unexpected (and undesired) things happen.
|
47
|
-
def load_prior_resource(*args)
|
48
|
-
Chef::Log.debug "Overloading #{self.resource_name} load_prior_resource with NOOP"
|
49
|
-
end
|
50
|
-
|
51
|
-
# chef client version and omnibus
|
52
|
-
# chef-zero boot method?
|
53
|
-
# chef-client -z boot method?
|
54
|
-
# pushy boot method?
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
1
|
+
require 'chef/resource/lwrp_base'
|
2
|
+
require 'cheffish'
|
3
|
+
require 'chef_metal'
|
4
|
+
require 'cheffish/merged_config'
|
5
|
+
|
6
|
+
class Chef
|
7
|
+
class Resource
|
8
|
+
class LoadBalancer < Chef::Resource::LWRPBase
|
9
|
+
|
10
|
+
self.resource_name = 'load_balancer'
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@chef_environment = run_context.cheffish.current_environment
|
15
|
+
@chef_server = run_context.cheffish.current_chef_server
|
16
|
+
@driver = run_context.chef_metal.current_driver
|
17
|
+
@load_balancer_options = run_context.chef_metal.current_load_balancer_options
|
18
|
+
end
|
19
|
+
|
20
|
+
actions :create, :destroy
|
21
|
+
default_action :create
|
22
|
+
|
23
|
+
# Driver attributes
|
24
|
+
attribute :driver
|
25
|
+
attribute :chef_server
|
26
|
+
attribute :load_balancer_options
|
27
|
+
attribute :name, :kind_of => String, :name_attribute => true
|
28
|
+
attribute :machines
|
29
|
+
|
30
|
+
def add_load_balancer_options(options)
|
31
|
+
@load_balancer_options = Cheffish::MergedConfig.new(options, @load_balancer_options)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# This is here because metal users will probably want to do things like:
|
36
|
+
# machine "foo"
|
37
|
+
# action :destroy
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# with_load_balancer_options :bootstrap_options => {...}
|
41
|
+
# machine "foo"
|
42
|
+
# converge true
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# Without this, the first resource's machine options will obliterate the second
|
46
|
+
# resource's machine options, and then unexpected (and undesired) things happen.
|
47
|
+
def load_prior_resource(*args)
|
48
|
+
Chef::Log.debug "Overloading #{self.resource_name} load_prior_resource with NOOP"
|
49
|
+
end
|
50
|
+
|
51
|
+
# chef client version and omnibus
|
52
|
+
# chef-zero boot method?
|
53
|
+
# chef-client -z boot method?
|
54
|
+
# pushy boot method?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,128 +1,128 @@
|
|
1
|
-
require 'chef/resource/lwrp_base'
|
2
|
-
require 'cheffish'
|
3
|
-
require 'chef/provisioning'
|
4
|
-
require 'cheffish/merged_config'
|
5
|
-
|
6
|
-
class Chef
|
7
|
-
class Resource
|
8
|
-
class Machine < Chef::Resource::LWRPBase
|
9
|
-
|
10
|
-
self.resource_name = 'machine'
|
11
|
-
|
12
|
-
def initialize(*args)
|
13
|
-
super
|
14
|
-
@chef_environment = run_context.cheffish.current_environment
|
15
|
-
@chef_server = run_context.cheffish.current_chef_server
|
16
|
-
@driver = run_context.chef_provisioning.current_driver
|
17
|
-
@machine_options = run_context.chef_provisioning.current_machine_options
|
18
|
-
end
|
19
|
-
|
20
|
-
actions :allocate, :ready, :setup, :converge, :converge_only, :destroy, :stop
|
21
|
-
default_action :converge
|
22
|
-
|
23
|
-
# Driver attributes
|
24
|
-
attribute :driver
|
25
|
-
|
26
|
-
# Machine options
|
27
|
-
attribute :machine_options
|
28
|
-
|
29
|
-
# This includes attributes from the Cheffish::Node resources - allows us
|
30
|
-
# to specify things like `run_list`, `chef_server`, etc.
|
31
|
-
Cheffish.node_attributes(self)
|
32
|
-
|
33
|
-
# Client keys
|
34
|
-
# Options to generate private key (size, type, etc.) when the server doesn't have it
|
35
|
-
attribute :private_key_options, :kind_of => Hash
|
36
|
-
attribute :allow_overwrite_keys, :kind_of => [TrueClass, FalseClass]
|
37
|
-
|
38
|
-
# Optionally pull the public key out to a file
|
39
|
-
attribute :public_key_path, :kind_of => String
|
40
|
-
attribute :public_key_format, :kind_of => String
|
41
|
-
|
42
|
-
# If you really want to force the private key to be a certain key, pass these
|
43
|
-
attribute :source_key
|
44
|
-
attribute :source_key_path, :kind_of => String
|
45
|
-
attribute :source_key_pass_phrase
|
46
|
-
|
47
|
-
# Client attributes
|
48
|
-
attribute :admin, :kind_of => [TrueClass, FalseClass]
|
49
|
-
attribute :validator, :kind_of => [TrueClass, FalseClass]
|
50
|
-
|
51
|
-
# Client Ohai hints, allows machine to enable hints
|
52
|
-
# e.g. ohai_hints 'ec2' => { 'a' => 'b' } creates file ec2.json with json contents { 'a': 'b' }
|
53
|
-
attribute :ohai_hints, :kind_of => Hash
|
54
|
-
|
55
|
-
# A string containing extra configuration for the machine
|
56
|
-
attribute :chef_config, :kind_of => String
|
57
|
-
|
58
|
-
# Allows you to turn convergence off in the :create action by writing "converge false"
|
59
|
-
# or force it with "true"
|
60
|
-
attribute :converge, :kind_of => [TrueClass, FalseClass]
|
61
|
-
|
62
|
-
# A list of files to upload, in the format REMOTE_PATH => LOCAL_PATH|HASH.
|
63
|
-
# == Examples
|
64
|
-
# files '/remote/path.txt' => '/local/path.txt'
|
65
|
-
# files '/remote/path.txt' => { :local_path => '/local/path.txt' }
|
66
|
-
# files '/remote/path.txt' => { :content => 'woo' }
|
67
|
-
attribute :files, :kind_of => Hash
|
68
|
-
|
69
|
-
# The named machine_image to start from. Specify the name of a machine_image
|
70
|
-
# object and the default machine_options will be set to use that image.
|
71
|
-
# == Examples
|
72
|
-
# from_image 'company_base_image'
|
73
|
-
attribute :from_image, :kind_of => String
|
74
|
-
|
75
|
-
# A single file to upload, in the format REMOTE_PATH, LOCAL_PATH|HASH.
|
76
|
-
# This directive may be passed multiple times, and multiple files will be uploaded.
|
77
|
-
# == Examples
|
78
|
-
# file '/remote/path.txt', '/local/path.txt'
|
79
|
-
# file '/remote/path.txt', { :local_path => '/local/path.txt' }
|
80
|
-
# file '/remote/path.txt', { :content => 'woo' }
|
81
|
-
def file(remote_path, local = nil)
|
82
|
-
@files ||= {}
|
83
|
-
if remote_path.is_a?(Hash)
|
84
|
-
if local
|
85
|
-
raise "file(Hash, something) does not make sense. Either pass a hash, or pass a pair, please."
|
86
|
-
end
|
87
|
-
remote_path.each_pair do |remote, local|
|
88
|
-
@files[remote] = local
|
89
|
-
end
|
90
|
-
elsif remote_path.is_a?(String)
|
91
|
-
if !local
|
92
|
-
raise "Must pass both a remote path and a local path to file directive"
|
93
|
-
end
|
94
|
-
@files[remote_path] = local
|
95
|
-
else
|
96
|
-
raise "file remote_path must be a String, but is a #{remote_path.class}"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def add_machine_options(options)
|
101
|
-
@machine_options = Cheffish::MergedConfig.new(options, @machine_options)
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
# This is here because provisioning users will probably want to do things like:
|
106
|
-
# machine "foo"
|
107
|
-
# action :destroy
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# @example
|
111
|
-
# with_machine_options :bootstrap_options => { ... }
|
112
|
-
# machine "foo"
|
113
|
-
# converge true
|
114
|
-
# end
|
115
|
-
#
|
116
|
-
# Without this, the first resource's machine options will obliterate the second
|
117
|
-
# resource's machine options, and then unexpected (and undesired) things happen.
|
118
|
-
def load_prior_resource(*args)
|
119
|
-
Chef::Log.debug "Overloading #{self.resource_name} load_prior_resource with NOOP"
|
120
|
-
end
|
121
|
-
|
122
|
-
# chef client version and omnibus
|
123
|
-
# chef-zero boot method?
|
124
|
-
# chef-client -z boot method?
|
125
|
-
# pushy boot method?
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
1
|
+
require 'chef/resource/lwrp_base'
|
2
|
+
require 'cheffish'
|
3
|
+
require 'chef/provisioning'
|
4
|
+
require 'cheffish/merged_config'
|
5
|
+
|
6
|
+
class Chef
|
7
|
+
class Resource
|
8
|
+
class Machine < Chef::Resource::LWRPBase
|
9
|
+
|
10
|
+
self.resource_name = 'machine'
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@chef_environment = run_context.cheffish.current_environment
|
15
|
+
@chef_server = run_context.cheffish.current_chef_server
|
16
|
+
@driver = run_context.chef_provisioning.current_driver
|
17
|
+
@machine_options = run_context.chef_provisioning.current_machine_options
|
18
|
+
end
|
19
|
+
|
20
|
+
actions :allocate, :ready, :setup, :converge, :converge_only, :destroy, :stop
|
21
|
+
default_action :converge
|
22
|
+
|
23
|
+
# Driver attributes
|
24
|
+
attribute :driver
|
25
|
+
|
26
|
+
# Machine options
|
27
|
+
attribute :machine_options
|
28
|
+
|
29
|
+
# This includes attributes from the Cheffish::Node resources - allows us
|
30
|
+
# to specify things like `run_list`, `chef_server`, etc.
|
31
|
+
Cheffish.node_attributes(self)
|
32
|
+
|
33
|
+
# Client keys
|
34
|
+
# Options to generate private key (size, type, etc.) when the server doesn't have it
|
35
|
+
attribute :private_key_options, :kind_of => Hash
|
36
|
+
attribute :allow_overwrite_keys, :kind_of => [TrueClass, FalseClass]
|
37
|
+
|
38
|
+
# Optionally pull the public key out to a file
|
39
|
+
attribute :public_key_path, :kind_of => String
|
40
|
+
attribute :public_key_format, :kind_of => String
|
41
|
+
|
42
|
+
# If you really want to force the private key to be a certain key, pass these
|
43
|
+
attribute :source_key
|
44
|
+
attribute :source_key_path, :kind_of => String
|
45
|
+
attribute :source_key_pass_phrase
|
46
|
+
|
47
|
+
# Client attributes
|
48
|
+
attribute :admin, :kind_of => [TrueClass, FalseClass]
|
49
|
+
attribute :validator, :kind_of => [TrueClass, FalseClass]
|
50
|
+
|
51
|
+
# Client Ohai hints, allows machine to enable hints
|
52
|
+
# e.g. ohai_hints 'ec2' => { 'a' => 'b' } creates file ec2.json with json contents { 'a': 'b' }
|
53
|
+
attribute :ohai_hints, :kind_of => Hash
|
54
|
+
|
55
|
+
# A string containing extra configuration for the machine
|
56
|
+
attribute :chef_config, :kind_of => String
|
57
|
+
|
58
|
+
# Allows you to turn convergence off in the :create action by writing "converge false"
|
59
|
+
# or force it with "true"
|
60
|
+
attribute :converge, :kind_of => [TrueClass, FalseClass]
|
61
|
+
|
62
|
+
# A list of files to upload, in the format REMOTE_PATH => LOCAL_PATH|HASH.
|
63
|
+
# == Examples
|
64
|
+
# files '/remote/path.txt' => '/local/path.txt'
|
65
|
+
# files '/remote/path.txt' => { :local_path => '/local/path.txt' }
|
66
|
+
# files '/remote/path.txt' => { :content => 'woo' }
|
67
|
+
attribute :files, :kind_of => Hash
|
68
|
+
|
69
|
+
# The named machine_image to start from. Specify the name of a machine_image
|
70
|
+
# object and the default machine_options will be set to use that image.
|
71
|
+
# == Examples
|
72
|
+
# from_image 'company_base_image'
|
73
|
+
attribute :from_image, :kind_of => String
|
74
|
+
|
75
|
+
# A single file to upload, in the format REMOTE_PATH, LOCAL_PATH|HASH.
|
76
|
+
# This directive may be passed multiple times, and multiple files will be uploaded.
|
77
|
+
# == Examples
|
78
|
+
# file '/remote/path.txt', '/local/path.txt'
|
79
|
+
# file '/remote/path.txt', { :local_path => '/local/path.txt' }
|
80
|
+
# file '/remote/path.txt', { :content => 'woo' }
|
81
|
+
def file(remote_path, local = nil)
|
82
|
+
@files ||= {}
|
83
|
+
if remote_path.is_a?(Hash)
|
84
|
+
if local
|
85
|
+
raise "file(Hash, something) does not make sense. Either pass a hash, or pass a pair, please."
|
86
|
+
end
|
87
|
+
remote_path.each_pair do |remote, local|
|
88
|
+
@files[remote] = local
|
89
|
+
end
|
90
|
+
elsif remote_path.is_a?(String)
|
91
|
+
if !local
|
92
|
+
raise "Must pass both a remote path and a local path to file directive"
|
93
|
+
end
|
94
|
+
@files[remote_path] = local
|
95
|
+
else
|
96
|
+
raise "file remote_path must be a String, but is a #{remote_path.class}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_machine_options(options)
|
101
|
+
@machine_options = Cheffish::MergedConfig.new(options, @machine_options)
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
# This is here because provisioning users will probably want to do things like:
|
106
|
+
# machine "foo"
|
107
|
+
# action :destroy
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# @example
|
111
|
+
# with_machine_options :bootstrap_options => { ... }
|
112
|
+
# machine "foo"
|
113
|
+
# converge true
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# Without this, the first resource's machine options will obliterate the second
|
117
|
+
# resource's machine options, and then unexpected (and undesired) things happen.
|
118
|
+
def load_prior_resource(*args)
|
119
|
+
Chef::Log.debug "Overloading #{self.resource_name} load_prior_resource with NOOP"
|
120
|
+
end
|
121
|
+
|
122
|
+
# chef client version and omnibus
|
123
|
+
# chef-zero boot method?
|
124
|
+
# chef-client -z boot method?
|
125
|
+
# pushy boot method?
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -1,78 +1,78 @@
|
|
1
|
-
require 'chef/resource/lwrp_base'
|
2
|
-
require 'chef/mixin/deep_merge'
|
3
|
-
|
4
|
-
class Chef
|
5
|
-
class Resource
|
6
|
-
class MachineBatch < Chef::Resource::LWRPBase
|
7
|
-
|
8
|
-
self.resource_name = 'machine_batch'
|
9
|
-
|
10
|
-
def initialize(*args)
|
11
|
-
super
|
12
|
-
@machines = []
|
13
|
-
@driver = run_context.chef_provisioning.current_driver
|
14
|
-
@chef_server = run_context.cheffish.current_chef_server
|
15
|
-
@machine_options = run_context.chef_provisioning.current_machine_options
|
16
|
-
end
|
17
|
-
|
18
|
-
actions :allocate, :ready, :setup, :converge, :converge_only, :destroy, :stop
|
19
|
-
default_action :converge
|
20
|
-
|
21
|
-
attribute :machines, :kind_of => [ Array ]
|
22
|
-
attribute :max_simultaneous, :kind_of => [ Integer ]
|
23
|
-
attribute :from_recipe
|
24
|
-
|
25
|
-
# These four attributes are for when you pass names or ManagedEntrys to
|
26
|
-
# "machines". Not used for auto-batch or explicit inline machine declarations.
|
27
|
-
attribute :driver
|
28
|
-
attribute :chef_server
|
29
|
-
attribute :machine_options
|
30
|
-
attribute :files, :kind_of => [ Array ]
|
31
|
-
|
32
|
-
def machines(*values)
|
33
|
-
if values.size == 0
|
34
|
-
@machines
|
35
|
-
else
|
36
|
-
@machines += values.flatten
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def machine(name, &block)
|
41
|
-
machines << from_recipe.build_resource(:machine, name, caller[0], &block)
|
42
|
-
end
|
43
|
-
|
44
|
-
def add_machine_options(options)
|
45
|
-
@machine_options = Chef::Mixin::DeepMerge.hash_only_merge(@machine_options, options)
|
46
|
-
end
|
47
|
-
|
48
|
-
# We override this because we want to hide @from_recipe and shorten @machines
|
49
|
-
# in error output.
|
50
|
-
def to_text
|
51
|
-
ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS - [ :@from_recipe, :@machines ]
|
52
|
-
text = "# Declared in #{@source_line}\n\n"
|
53
|
-
text << self.class.dsl_name + "(\"#{name}\") do\n"
|
54
|
-
ivars.each do |ivar|
|
55
|
-
if (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?)
|
56
|
-
value_string = value.respond_to?(:to_text) ? value.to_text : value.inspect
|
57
|
-
text << " #{ivar.to_s.sub(/^@/,'')} #{value_string}\n"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
machine_names = @machines.map do |m|
|
61
|
-
if m.is_a?(Chef::Provisioning::ManagedEntry)
|
62
|
-
m.name
|
63
|
-
elsif m.is_a?(Chef::Resource::Machine)
|
64
|
-
m.name
|
65
|
-
else
|
66
|
-
m
|
67
|
-
end
|
68
|
-
end
|
69
|
-
text << " machines #{machine_names.inspect}\n"
|
70
|
-
[@not_if, @only_if].flatten.each do |conditional|
|
71
|
-
text << " #{conditional.to_text}\n"
|
72
|
-
end
|
73
|
-
text << "end\n"
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
require 'chef/resource/lwrp_base'
|
2
|
+
require 'chef/mixin/deep_merge'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Resource
|
6
|
+
class MachineBatch < Chef::Resource::LWRPBase
|
7
|
+
|
8
|
+
self.resource_name = 'machine_batch'
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
super
|
12
|
+
@machines = []
|
13
|
+
@driver = run_context.chef_provisioning.current_driver
|
14
|
+
@chef_server = run_context.cheffish.current_chef_server
|
15
|
+
@machine_options = run_context.chef_provisioning.current_machine_options
|
16
|
+
end
|
17
|
+
|
18
|
+
actions :allocate, :ready, :setup, :converge, :converge_only, :destroy, :stop
|
19
|
+
default_action :converge
|
20
|
+
|
21
|
+
attribute :machines, :kind_of => [ Array ]
|
22
|
+
attribute :max_simultaneous, :kind_of => [ Integer ]
|
23
|
+
attribute :from_recipe
|
24
|
+
|
25
|
+
# These four attributes are for when you pass names or ManagedEntrys to
|
26
|
+
# "machines". Not used for auto-batch or explicit inline machine declarations.
|
27
|
+
attribute :driver
|
28
|
+
attribute :chef_server
|
29
|
+
attribute :machine_options
|
30
|
+
attribute :files, :kind_of => [ Array ]
|
31
|
+
|
32
|
+
def machines(*values)
|
33
|
+
if values.size == 0
|
34
|
+
@machines
|
35
|
+
else
|
36
|
+
@machines += values.flatten
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def machine(name, &block)
|
41
|
+
machines << from_recipe.build_resource(:machine, name, caller[0], &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_machine_options(options)
|
45
|
+
@machine_options = Chef::Mixin::DeepMerge.hash_only_merge(@machine_options, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
# We override this because we want to hide @from_recipe and shorten @machines
|
49
|
+
# in error output.
|
50
|
+
def to_text
|
51
|
+
ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS - [ :@from_recipe, :@machines ]
|
52
|
+
text = "# Declared in #{@source_line}\n\n"
|
53
|
+
text << self.class.dsl_name + "(\"#{name}\") do\n"
|
54
|
+
ivars.each do |ivar|
|
55
|
+
if (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?)
|
56
|
+
value_string = value.respond_to?(:to_text) ? value.to_text : value.inspect
|
57
|
+
text << " #{ivar.to_s.sub(/^@/,'')} #{value_string}\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
machine_names = @machines.map do |m|
|
61
|
+
if m.is_a?(Chef::Provisioning::ManagedEntry)
|
62
|
+
m.name
|
63
|
+
elsif m.is_a?(Chef::Resource::Machine)
|
64
|
+
m.name
|
65
|
+
else
|
66
|
+
m
|
67
|
+
end
|
68
|
+
end
|
69
|
+
text << " machines #{machine_names.inspect}\n"
|
70
|
+
[@not_if, @only_if].flatten.each do |conditional|
|
71
|
+
text << " #{conditional.to_text}\n"
|
72
|
+
end
|
73
|
+
text << "end\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|