chef-metal-vagrant 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef_metal_vagrant/vagrant_provisioner.rb +68 -51
- data/lib/chef_metal_vagrant/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: c87c1ff4863d5dd308daf58ae90f1acb12ddc8eb
|
4
|
+
data.tar.gz: 3f32ecaad5a7075fb4551486ec2d55a97df2e665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4467be72de80093ae76247ef90b1b664ec4957d5bf6f057501db8190cea53bf24f3532ea9c5a3d8e4952f154cfafae8cefce8809ea24657877c28e3423d4f9e4
|
7
|
+
data.tar.gz: d8c1fc591cfc9456dd278d54e7af7e5bb7c838317001245cbf35d3fe6aadc38b46e4b874e1b4f26062719216eb70e9da86f03a08a165fc9556195b096fc9de13
|
@@ -55,7 +55,7 @@ module ChefMetalVagrant
|
|
55
55
|
# instead of options provided by the provisioner. TODO compare and
|
56
56
|
# fail if different?
|
57
57
|
# node will have node['normal']['provisioner_options'] in it with any options.
|
58
|
-
# It is a hash with this format:
|
58
|
+
# It is a hash with this format (all keys are strings):
|
59
59
|
#
|
60
60
|
# -- provisioner_url: vagrant:<cluster_path>
|
61
61
|
# -- vagrant_options: hash of properties of the "config"
|
@@ -71,6 +71,8 @@ module ChefMetalVagrant
|
|
71
71
|
# is detected.
|
72
72
|
# -- up_timeout: maximum time, in seconds, to wait for vagrant
|
73
73
|
# to bring up the machine. Defaults to 10 minutes.
|
74
|
+
# -- chef_client_timeout: maximum time, in seconds, to wait for chef-client
|
75
|
+
# to complete. 0 or nil for no timeout. Defaults to 2 hours.
|
74
76
|
#
|
75
77
|
# node['normal']['provisioner_output'] will be populated with information
|
76
78
|
# about the created machine. For vagrant, it is a hash with this
|
@@ -83,7 +85,7 @@ module ChefMetalVagrant
|
|
83
85
|
# -- forwarded_ports: hash with key as guest_port => host_port
|
84
86
|
#
|
85
87
|
def acquire_machine(action_handler, node)
|
86
|
-
# Set up the
|
88
|
+
# Set up the provisioner output
|
87
89
|
provisioner_options = node['normal']['provisioner_options']
|
88
90
|
vm_name = node['name']
|
89
91
|
old_provisioner_output = node['normal']['provisioner_output']
|
@@ -99,50 +101,12 @@ module ChefMetalVagrant
|
|
99
101
|
# over (perhaps introduce a boolean that will force a delete and recreate
|
100
102
|
# in such a case)
|
101
103
|
|
102
|
-
#
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
vm_file_content << " config.#{key} = #{value.inspect}\n"
|
109
|
-
end
|
110
|
-
vm_file_content << provisioner_options['vagrant_config'] if provisioner_options['vagrant_config']
|
111
|
-
vm_file_content << " end\nend\n"
|
112
|
-
|
113
|
-
# Set up vagrant file
|
114
|
-
vm_file = ChefMetal.inline_resource(action_handler) do
|
115
|
-
file provisioner_output['vm_file_path'] do
|
116
|
-
content vm_file_content
|
117
|
-
action :create
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Check current status of vm
|
122
|
-
current_status = vagrant_status(vm_name)
|
123
|
-
up_timeout = provisioner_options['up_timeout'] || 10*60
|
124
|
-
|
125
|
-
if current_status != 'running'
|
126
|
-
# Run vagrant up if vm is not running
|
127
|
-
action_handler.perform_action "run vagrant up #{vm_name} (status was '#{current_status}')" do
|
128
|
-
result = shell_out("vagrant up #{vm_name}", :cwd => cluster_path, :timeout => up_timeout)
|
129
|
-
if result.exitstatus != 0
|
130
|
-
raise "vagrant up #{vm_name} failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
131
|
-
end
|
132
|
-
parse_vagrant_up(result.stdout, node)
|
133
|
-
end
|
134
|
-
elsif vm_file.updated_by_last_action?
|
135
|
-
# Run vagrant reload if vm is running and vm file changed
|
136
|
-
action_handler.perform_action "run vagrant reload #{vm_name}" do
|
137
|
-
result = shell_out("vagrant reload #{vm_name}", :cwd => cluster_path, :timeout => up_timeout)
|
138
|
-
if result.exitstatus != 0
|
139
|
-
raise "vagrant reload #{vm_name} failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
140
|
-
end
|
141
|
-
parse_vagrant_up(result.stdout, node)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
# Create machine object for callers to use
|
104
|
+
#
|
105
|
+
# This is where the work gets done:
|
106
|
+
# Create the .vm file, start the vm, and return the Machine
|
107
|
+
#
|
108
|
+
vm_file = create_vm_file(action_handler, vm_name, provisioner_output['vm_file_path'], provisioner_options)
|
109
|
+
start_machine(action_handler, vm_name, vm_file, provisioner_output, provisioner_options['up_timeout'])
|
146
110
|
machine_for(node)
|
147
111
|
end
|
148
112
|
|
@@ -214,18 +178,65 @@ module ChefMetalVagrant
|
|
214
178
|
"vagrant_cluster://#{action_handler.node['name']}#{cluster_path}"
|
215
179
|
end
|
216
180
|
|
217
|
-
def
|
181
|
+
def create_vm_file(action_handler, vm_name, vm_file_path, provisioner_options)
|
182
|
+
# Determine contents of vm file
|
183
|
+
vm_file_content = "Vagrant.configure('2') do |outer_config|\n"
|
184
|
+
vm_file_content << " outer_config.vm.define #{vm_name.inspect} do |config|\n"
|
185
|
+
merged_vagrant_options = { 'vm.hostname' => vm_name }
|
186
|
+
merged_vagrant_options.merge!(provisioner_options['vagrant_options']) if provisioner_options['vagrant_options']
|
187
|
+
merged_vagrant_options.each_pair do |key, value|
|
188
|
+
vm_file_content << " config.#{key} = #{value.inspect}\n"
|
189
|
+
end
|
190
|
+
vm_file_content << provisioner_options['vagrant_config'] if provisioner_options['vagrant_config']
|
191
|
+
vm_file_content << " end\nend\n"
|
192
|
+
|
193
|
+
# Set up vagrant file
|
194
|
+
ChefMetal.inline_resource(action_handler) do
|
195
|
+
file vm_file_path do
|
196
|
+
content vm_file_content
|
197
|
+
action :create
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def start_machine(action_handler, vm_name, vm_file, provisioner_output, up_timeout)
|
203
|
+
# Check current status of vm
|
204
|
+
current_status = vagrant_status(vm_name)
|
205
|
+
up_timeout ||= 10*60
|
206
|
+
|
207
|
+
if current_status != 'running'
|
208
|
+
# Run vagrant up if vm is not running
|
209
|
+
action_handler.perform_action "run vagrant up #{vm_name} (status was '#{current_status}')" do
|
210
|
+
result = shell_out("vagrant up #{vm_name}", :cwd => cluster_path, :timeout => up_timeout)
|
211
|
+
if result.exitstatus != 0
|
212
|
+
raise "vagrant up #{vm_name} failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
213
|
+
end
|
214
|
+
parse_vagrant_up(result.stdout, provisioner_output)
|
215
|
+
end
|
216
|
+
elsif vm_file.updated_by_last_action?
|
217
|
+
# Run vagrant reload if vm is running and vm file changed
|
218
|
+
action_handler.perform_action "run vagrant reload #{vm_name}" do
|
219
|
+
result = shell_out("vagrant reload #{vm_name}", :cwd => cluster_path, :timeout => up_timeout)
|
220
|
+
if result.exitstatus != 0
|
221
|
+
raise "vagrant reload #{vm_name} failed!\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
|
222
|
+
end
|
223
|
+
parse_vagrant_up(result.stdout, provisioner_output)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def parse_vagrant_up(output, provisioner_output)
|
218
229
|
# Grab forwarded port info
|
230
|
+
provisioner_output['forwarded_ports'] = {}
|
219
231
|
in_forwarding_ports = false
|
220
232
|
output.lines.each do |line|
|
221
233
|
if in_forwarding_ports
|
222
234
|
if line =~ /-- (\d+) => (\d+)/
|
223
|
-
|
235
|
+
provisioner_output['forwarded_ports'][$1] = $2
|
224
236
|
else
|
225
237
|
in_forwarding_ports = false
|
226
238
|
end
|
227
239
|
elsif line =~ /Forwarding ports...$/
|
228
|
-
node['normal']['provisioner_output']['forwarded_ports'] = {}
|
229
240
|
in_forwarding_ports = true
|
230
241
|
end
|
231
242
|
end
|
@@ -242,11 +253,17 @@ module ChefMetalVagrant
|
|
242
253
|
def convergence_strategy_for(node)
|
243
254
|
if vagrant_option(node, 'vm.guest').to_s == 'windows'
|
244
255
|
@windows_convergence_strategy ||= begin
|
245
|
-
|
256
|
+
options = {}
|
257
|
+
provisioner_options = node['normal']['provisioner_options'] || {}
|
258
|
+
options[:chef_client_timeout] = provisioner_options['chef_client_timeout'] if provisioner_options.has_key?('chef_client_timeout')
|
259
|
+
ChefMetal::ConvergenceStrategy::InstallMsi.new(options)
|
246
260
|
end
|
247
261
|
else
|
248
262
|
@unix_convergence_strategy ||= begin
|
249
|
-
|
263
|
+
options = {}
|
264
|
+
provisioner_options = node['normal']['provisioner_options'] || {}
|
265
|
+
options[:chef_client_timeout] = provisioner_options['chef_client_timeout'] if provisioner_options.has_key?('chef_client_timeout')
|
266
|
+
ChefMetal::ConvergenceStrategy::InstallCached.new(options)
|
250
267
|
end
|
251
268
|
end
|
252
269
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-metal-vagrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
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-04-
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|