chef-metal 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/provider/fog_key_pair.rb +3 -0
- data/lib/chef/provider/machine.rb +3 -0
- data/lib/chef/provider/machine_file.rb +8 -1
- data/lib/chef/provider/vagrant_cluster.rb +3 -0
- data/lib/chef/resource/machine_file.rb +4 -0
- data/lib/chef_metal.rb +16 -2
- data/lib/chef_metal/action_handler.rb +49 -0
- data/lib/chef_metal/convergence_strategy.rb +5 -5
- data/lib/chef_metal/convergence_strategy/install_cached.rb +19 -19
- data/lib/chef_metal/convergence_strategy/install_msi.rb +4 -4
- data/lib/chef_metal/convergence_strategy/install_sh.rb +5 -5
- data/lib/chef_metal/convergence_strategy/no_converge.rb +34 -0
- data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +13 -12
- data/lib/chef_metal/inline_resource.rb +16 -13
- data/lib/chef_metal/machine.rb +12 -12
- data/lib/chef_metal/machine/basic_machine.rb +14 -14
- data/lib/chef_metal/machine/unix_machine.rb +17 -23
- data/lib/chef_metal/machine/windows_machine.rb +6 -6
- data/lib/chef_metal/provider_action_handler.rb +41 -0
- data/lib/chef_metal/provisioner.rb +19 -4
- data/lib/chef_metal/provisioner/fog_provisioner.rb +56 -28
- data/lib/chef_metal/provisioner/vagrant_provisioner.rb +32 -15
- data/lib/chef_metal/provisioner_init/fog_init.rb +4 -0
- data/lib/chef_metal/provisioner_init/vagrant_cluster_init.rb +4 -0
- data/lib/chef_metal/transport/ssh.rb +9 -1
- data/lib/chef_metal/version.rb +1 -1
- metadata +7 -2
@@ -8,7 +8,6 @@ module ChefMetal
|
|
8
8
|
class VagrantProvisioner < Provisioner
|
9
9
|
|
10
10
|
include Chef::Mixin::ShellOut
|
11
|
-
|
12
11
|
# Create a new vagrant provisioner.
|
13
12
|
#
|
14
13
|
# ## Parameters
|
@@ -20,6 +19,20 @@ module ChefMetal
|
|
20
19
|
|
21
20
|
attr_reader :cluster_path
|
22
21
|
|
22
|
+
# Inflate a provisioner from node information; we don't want to force the
|
23
|
+
# driver to figure out what the provisioner really needs, since it varies
|
24
|
+
# from provisioner to provisioner.
|
25
|
+
#
|
26
|
+
# ## Parameters
|
27
|
+
# node - node to inflate the provisioner for
|
28
|
+
#
|
29
|
+
# returns a VagrantProvisioner
|
30
|
+
def self.inflate(node)
|
31
|
+
node_url = node['normal']['provisioner_output']['provisioner_url']
|
32
|
+
cluster_path = node_url.split(':', 2)[1].sub(/^\/\//, "")
|
33
|
+
self.new(cluster_path)
|
34
|
+
end
|
35
|
+
|
23
36
|
# Acquire a machine, generally by provisioning it. Returns a Machine
|
24
37
|
# object pointing at the machine, allowing useful actions like setup,
|
25
38
|
# converge, execute, file and directory. The Machine object will have a
|
@@ -27,7 +40,11 @@ module ChefMetal
|
|
27
40
|
# different from the original node object).
|
28
41
|
#
|
29
42
|
# ## Parameters
|
30
|
-
#
|
43
|
+
# action_handler - the action_handler object that is calling this method; this
|
44
|
+
# is generally a action_handler, but could be anything that can support the
|
45
|
+
# ChefMetal::ActionHandler interface (i.e., in the case of the test
|
46
|
+
# kitchen metal driver for acquiring and destroying VMs; see the base
|
47
|
+
# class for what needs providing).
|
31
48
|
# node - node object (deserialized json) representing this machine. If
|
32
49
|
# the node has a provisioner_options hash in it, these will be used
|
33
50
|
# instead of options provided by the provisioner. TODO compare and
|
@@ -60,13 +77,13 @@ module ChefMetal
|
|
60
77
|
# on disk
|
61
78
|
# -- forwarded_ports: hash with key as guest_port => host_port
|
62
79
|
#
|
63
|
-
def acquire_machine(
|
80
|
+
def acquire_machine(action_handler, node)
|
64
81
|
# Set up the modified node data
|
65
82
|
provisioner_options = node['normal']['provisioner_options']
|
66
83
|
vm_name = node['name']
|
67
84
|
old_provisioner_output = node['normal']['provisioner_output']
|
68
85
|
node['normal']['provisioner_output'] = provisioner_output = {
|
69
|
-
'provisioner_url' => provisioner_url(
|
86
|
+
'provisioner_url' => provisioner_url(action_handler),
|
70
87
|
'vm_name' => vm_name,
|
71
88
|
'vm_file_path' => File.join(cluster_path, "#{vm_name}.vm")
|
72
89
|
}
|
@@ -89,7 +106,7 @@ module ChefMetal
|
|
89
106
|
vm_file_content << " end\nend\n"
|
90
107
|
|
91
108
|
# Set up vagrant file
|
92
|
-
vm_file = ChefMetal.inline_resource(
|
109
|
+
vm_file = ChefMetal.inline_resource(action_handler) do
|
93
110
|
file provisioner_output['vm_file_path'] do
|
94
111
|
content vm_file_content
|
95
112
|
action :create
|
@@ -102,7 +119,7 @@ module ChefMetal
|
|
102
119
|
|
103
120
|
if current_status != 'running'
|
104
121
|
# Run vagrant up if vm is not running
|
105
|
-
|
122
|
+
action_handler.perform_action "run vagrant up #{vm_name} (status was '#{current_status}')" do
|
106
123
|
result = shell_out("vagrant up #{vm_name}", :cwd => cluster_path, :timeout => up_timeout)
|
107
124
|
if result.exitstatus != 0
|
108
125
|
raise "vagrant up #{vm_name} failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
@@ -111,7 +128,7 @@ module ChefMetal
|
|
111
128
|
end
|
112
129
|
elsif vm_file.updated_by_last_action?
|
113
130
|
# Run vagrant reload if vm is running and vm file changed
|
114
|
-
|
131
|
+
action_handler.perform_action "run vagrant reload #{vm_name}" do
|
115
132
|
result = shell_out("vagrant reload #{vm_name}", :cwd => cluster_path, :timeout => up_timeout)
|
116
133
|
if result.exitstatus != 0
|
117
134
|
raise "vagrant reload #{vm_name} failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
@@ -129,7 +146,7 @@ module ChefMetal
|
|
129
146
|
machine_for(node)
|
130
147
|
end
|
131
148
|
|
132
|
-
def delete_machine(
|
149
|
+
def delete_machine(action_handler, node)
|
133
150
|
if node['normal'] && node['normal']['provisioner_output']
|
134
151
|
provisioner_output = node['normal']['provisioner_output']
|
135
152
|
else
|
@@ -138,7 +155,7 @@ module ChefMetal
|
|
138
155
|
vm_name = provisioner_output['vm_name'] || node['name']
|
139
156
|
current_status = vagrant_status(vm_name)
|
140
157
|
if current_status != 'not created'
|
141
|
-
|
158
|
+
action_handler.perform_action "run vagrant destroy -f #{vm_name} (status was '#{current_status}')" do
|
142
159
|
result = shell_out("vagrant destroy -f #{vm_name}", :cwd => cluster_path)
|
143
160
|
if result.exitstatus != 0
|
144
161
|
raise "vagrant destroy failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
@@ -146,17 +163,17 @@ module ChefMetal
|
|
146
163
|
end
|
147
164
|
end
|
148
165
|
|
149
|
-
convergence_strategy_for(node).
|
166
|
+
convergence_strategy_for(node).cleanup_convergence(action_handler, node)
|
150
167
|
|
151
168
|
vm_file_path = provisioner_output['vm_file_path'] || File.join(cluster_path, "#{vm_name}.vm")
|
152
|
-
ChefMetal.inline_resource(
|
169
|
+
ChefMetal.inline_resource(action_handler) do
|
153
170
|
file vm_file_path do
|
154
171
|
action :delete
|
155
172
|
end
|
156
173
|
end
|
157
174
|
end
|
158
175
|
|
159
|
-
def stop_machine(
|
176
|
+
def stop_machine(action_handler, node)
|
160
177
|
if node['normal'] && node['normal']['provisioner_output']
|
161
178
|
provisioner_output = node['normal']['provisioner_output']
|
162
179
|
else
|
@@ -165,7 +182,7 @@ module ChefMetal
|
|
165
182
|
vm_name = provisioner_output['vm_name'] || node['name']
|
166
183
|
current_status = vagrant_status(vm_name)
|
167
184
|
if current_status == 'running'
|
168
|
-
|
185
|
+
action_handler.perform_action "run vagrant halt #{vm_name} (status was '#{current_status}')" do
|
169
186
|
result = shell_out("vagrant halt #{vm_name}", :cwd => cluster_path)
|
170
187
|
if result.exitstatus != 0
|
171
188
|
raise "vagrant halt failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
@@ -188,8 +205,8 @@ module ChefMetal
|
|
188
205
|
|
189
206
|
protected
|
190
207
|
|
191
|
-
def provisioner_url(
|
192
|
-
"vagrant_cluster://#{
|
208
|
+
def provisioner_url(action_handler)
|
209
|
+
"vagrant_cluster://#{action_handler.node['name']}#{cluster_path}"
|
193
210
|
end
|
194
211
|
|
195
212
|
def parse_vagrant_up(output, node)
|
@@ -23,6 +23,14 @@ module ChefMetal
|
|
23
23
|
stderr = ''
|
24
24
|
exitstatus = nil
|
25
25
|
channel = session.open_channel do |channel|
|
26
|
+
# Enable PTY unless otherwise specified, some instances require this
|
27
|
+
unless options[:ssh_pty_enable] == false
|
28
|
+
channel.request_pty do |chan, success|
|
29
|
+
raise "could not get pty" if !success && options[:ssh_pty_enable]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
26
34
|
channel.exec("#{options[:prefix]}#{command}") do |ch, success|
|
27
35
|
raise "could not execute command: #{command.inspect}" unless success
|
28
36
|
|
@@ -154,4 +162,4 @@ module ChefMetal
|
|
154
162
|
end
|
155
163
|
end
|
156
164
|
end
|
157
|
-
end
|
165
|
+
end
|
data/lib/chef_metal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-metal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -129,10 +129,12 @@ files:
|
|
129
129
|
- lib/chef/resource/machine_file.rb
|
130
130
|
- lib/chef/resource/vagrant_box.rb
|
131
131
|
- lib/chef/resource/vagrant_cluster.rb
|
132
|
+
- lib/chef_metal/action_handler.rb
|
132
133
|
- lib/chef_metal/aws_credentials.rb
|
133
134
|
- lib/chef_metal/convergence_strategy/install_cached.rb
|
134
135
|
- lib/chef_metal/convergence_strategy/install_msi.rb
|
135
136
|
- lib/chef_metal/convergence_strategy/install_sh.rb
|
137
|
+
- lib/chef_metal/convergence_strategy/no_converge.rb
|
136
138
|
- lib/chef_metal/convergence_strategy/precreate_chef_objects.rb
|
137
139
|
- lib/chef_metal/convergence_strategy.rb
|
138
140
|
- lib/chef_metal/fog.rb
|
@@ -142,9 +144,12 @@ files:
|
|
142
144
|
- lib/chef_metal/machine/windows_machine.rb
|
143
145
|
- lib/chef_metal/machine.rb
|
144
146
|
- lib/chef_metal/openstack_credentials.rb
|
147
|
+
- lib/chef_metal/provider_action_handler.rb
|
145
148
|
- lib/chef_metal/provisioner/fog_provisioner.rb
|
146
149
|
- lib/chef_metal/provisioner/vagrant_provisioner.rb
|
147
150
|
- lib/chef_metal/provisioner.rb
|
151
|
+
- lib/chef_metal/provisioner_init/fog_init.rb
|
152
|
+
- lib/chef_metal/provisioner_init/vagrant_cluster_init.rb
|
148
153
|
- lib/chef_metal/recipe_dsl.rb
|
149
154
|
- lib/chef_metal/transport/ssh.rb
|
150
155
|
- lib/chef_metal/transport/winrm.rb
|