blackstack-deployer 1.2.16 → 1.2.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blackstack-deployer.rb +49 -38
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e60ac86398b508a3c0262ee2a8d19d41e59994dbe293de5d155c68b0681d75a
|
4
|
+
data.tar.gz: 6054c1d54a2c3da6bea3b8e30ad1168c09450039918eeed55f1e1380deb7f01f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 441321acb984529b0d4fceb4b6b25cd6d7264731019d6076df6c8b5c65026345e9f7cab72c2b12df6843bedae5520b4b8dd6745d87e388057938a861a7ccd055
|
7
|
+
data.tar.gz: 5f487e1c15d30092ca92583eb98e0438334350cda2d719e77b18a03a416f7cfcb34fadd452de992c83b482f1c2b20c9c33cc1f9f0ea572825bf5f35348a1d1fd
|
data/lib/blackstack-deployer.rb
CHANGED
@@ -213,6 +213,9 @@ module BlackStack
|
|
213
213
|
# validate: existis a routine with a the value c[:command].to_s on its :name key
|
214
214
|
errors << "The routine with the name #{c[:command].to_s} does not exist" unless BlackStack::Deployer::deployment_routines.select { |r| r.name == c[:command].to_s }.size > 0
|
215
215
|
end
|
216
|
+
else
|
217
|
+
# validate: each line of the :command value must finish with ;
|
218
|
+
errors << "Each line in the :command value must finish with `;`.\nCommand: #{c[:command]}.\nRefer https://github.com/leandrosardi/blackstack-deployer#67-running-commands-in-background for more details." unless c[:command].strip.split("\n").select { |l| l.strip[-1,1] != ';' }.size == 0
|
216
219
|
end
|
217
220
|
|
218
221
|
# if c[:matches] exists
|
@@ -297,68 +300,76 @@ module BlackStack
|
|
297
300
|
h
|
298
301
|
end # def to_hash
|
299
302
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
# if code is a symbol
|
307
|
-
if code.is_a?(Symbol)
|
308
|
-
|
309
|
-
# if code is equel than :reboot
|
310
|
-
if code == :reboot
|
311
|
-
# call the node reboot method
|
312
|
-
node.reboot
|
313
|
-
else
|
314
|
-
# look for a routine with this name
|
315
|
-
r = BlackStack::Deployer.routines.select { |r| r.name == code.to_s }.first
|
316
|
-
if !r.nil?
|
317
|
-
r.run(node)
|
318
|
-
else
|
319
|
-
raise "The routine #{code.to_s} does not exist"
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
# if code is a string
|
324
|
-
elsif code.is_a?(String)
|
303
|
+
# return the code to exectute the command,
|
304
|
+
# after applying modifications requested by
|
305
|
+
# some parameters like `:show_outut` or `:background`.
|
306
|
+
def code(node)
|
307
|
+
ret = self.command
|
325
308
|
# replacing parameters
|
326
|
-
|
309
|
+
ret.scan(/%[a-zA-Z0-9\_]+%/).each do |p|
|
327
310
|
if p == '%eth0_ip%' # reserved parameter
|
328
311
|
# TODO: move the method eth0_ip to the blackstack-nodes library
|
329
|
-
|
312
|
+
ret.gsub!(p, node.eth0_ip)
|
330
313
|
elsif p == '%timestamp%' # reserved parameter
|
331
314
|
# TODO: move this to a timestamp function on blackstack-core
|
332
|
-
|
315
|
+
ret.gsub!(p, Time.now.to_s.gsub(/\D/, ''))
|
333
316
|
else
|
334
317
|
if node.parameters.has_key?(p.gsub(/%/, '').to_sym)
|
335
|
-
|
318
|
+
ret.gsub!(p, node.parameters[p.gsub(/%/, '').to_sym].to_s)
|
336
319
|
else
|
337
320
|
raise "The parameter #{p} does not exist in the node descriptor #{node.parameters.to_s}"
|
338
321
|
end
|
339
322
|
end
|
340
323
|
end
|
341
|
-
|
342
|
-
# if the command is configured to run in background, and the flag show_ouput is off, then modify the code to run in background
|
324
|
+
# if the command is configured to run in background, and the flag show_ouput is off, then modify the ret to run in background
|
343
325
|
if self.background && !BlackStack::Deployer.show_output
|
344
|
-
lines =
|
326
|
+
lines = ret.strip.lines
|
345
327
|
total = lines.size
|
346
328
|
i = 0
|
347
329
|
lines.each { |l|
|
348
330
|
i += 1
|
349
331
|
if i == total
|
350
|
-
l.gsub!(/;$/, '> /dev/null 2>&1 &')
|
332
|
+
l.gsub!(/;$/, ' > /dev/null 2>&1 &')
|
351
333
|
else
|
352
|
-
l.gsub!(/;$/, '> /dev/null 2>&1;')
|
334
|
+
l.gsub!(/;$/, ' > /dev/null 2>&1;')
|
353
335
|
end
|
354
336
|
}
|
355
|
-
|
337
|
+
ret = lines.join("\n")
|
356
338
|
end
|
339
|
+
# return the code
|
340
|
+
ret
|
341
|
+
end
|
342
|
+
|
343
|
+
def run(node)
|
344
|
+
l = BlackStack::Deployer.logger
|
345
|
+
errors = []
|
346
|
+
output = nil
|
347
|
+
s = self.code(node)
|
348
|
+
|
349
|
+
# if self.command is a symbol
|
350
|
+
if self.command.is_a?(Symbol)
|
351
|
+
|
352
|
+
# if self.command is equel than :reboot
|
353
|
+
if self.command == :reboot
|
354
|
+
# call the node reboot method
|
355
|
+
node.reboot
|
356
|
+
else
|
357
|
+
# look for a routine with this name
|
358
|
+
r = BlackStack::Deployer.routines.select { |r| r.name == self.command.to_s }.first
|
359
|
+
if !r.nil?
|
360
|
+
r.run(node)
|
361
|
+
else
|
362
|
+
raise "The routine #{self.command.to_s} does not exist"
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
# if self.command is a string
|
367
|
+
elsif self.command.is_a?(String)
|
357
368
|
|
358
369
|
# running the command
|
359
370
|
l.logs "Show command output... " if BlackStack::Deployer.show_output
|
360
|
-
l.log "\n\nCommand:\n--------\n\n#{
|
361
|
-
output = node.exec(
|
371
|
+
l.log "\n\nCommand:\n--------\n\n#{s} " if BlackStack::Deployer.show_output
|
372
|
+
output = node.exec(s, self.sudo)
|
362
373
|
l.log "\n\nOutput:\n-------\n\n#{output}" if BlackStack::Deployer.show_output
|
363
374
|
l.logf('done tracing.') if BlackStack::Deployer.show_output
|
364
375
|
|
@@ -382,7 +393,7 @@ module BlackStack
|
|
382
393
|
# return a hash descriptor of the command result
|
383
394
|
{
|
384
395
|
:command => self.command,
|
385
|
-
:code =>
|
396
|
+
:code => s,
|
386
397
|
:output => output,
|
387
398
|
:errors => errors,
|
388
399
|
}
|