blackstack-deployer 1.2.15 → 1.2.18
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 +95 -38
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1b14b1870b2b15b1f26f5b6087e4ceb672e375fce44d02ea7ae36d658d690c3
|
4
|
+
data.tar.gz: ff442f3dc4231513d28147431c859bc0791114a57d7085e90903e6aa7a09b7b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1080f3ec0c42bd3d0d47405f988a7ce6d3173340026c570b1442e2cbcb83ad68169eecb8987f61317a3adfce36f23f5cbabd56d1341ac2c027a06841dff89824
|
7
|
+
data.tar.gz: d11e282d1b7653cdb69c567f865f23a82d1a6b147f2e0258bd5e1371b92cf5864f17173a81c505010384e95b923c7bcf208e69a06cb25905151170e39e05cbce
|
data/lib/blackstack-deployer.rb
CHANGED
@@ -5,14 +5,25 @@ module BlackStack
|
|
5
5
|
# Deployer is a library that can be used to deploy a cluster of nodes.
|
6
6
|
module Deployer
|
7
7
|
@@logger = BlackStack::BaseLogger.new(nil)
|
8
|
+
@@show_output = false
|
8
9
|
@@nodes = []
|
9
10
|
@@routines = []
|
10
11
|
|
12
|
+
# set show_output
|
13
|
+
def self.set_show_output(value)
|
14
|
+
@@show_output = value
|
15
|
+
end
|
16
|
+
|
11
17
|
# set the logger
|
12
18
|
def self.set_logger(i_logger)
|
13
19
|
@@logger = i_logger
|
14
20
|
end
|
15
21
|
|
22
|
+
# get show_output
|
23
|
+
def self.show_output
|
24
|
+
@@show_output
|
25
|
+
end
|
26
|
+
|
16
27
|
# get the logger assigned to the module
|
17
28
|
def self.logger
|
18
29
|
@@logger
|
@@ -165,8 +176,8 @@ module BlackStack
|
|
165
176
|
if h[:errors].size == 0
|
166
177
|
#BlackStack::Deployer.logger.done
|
167
178
|
else
|
168
|
-
BlackStack::Deployer.logger.logf('error: ' + h.to_s)
|
169
|
-
raise "Error running command
|
179
|
+
#BlackStack::Deployer.logger.logf('error: ' + h.to_s)
|
180
|
+
raise "Error running command:\n#{h[:errors].uniq.join("\n")}"
|
170
181
|
end
|
171
182
|
end
|
172
183
|
ret
|
@@ -175,7 +186,7 @@ module BlackStack
|
|
175
186
|
|
176
187
|
# define attributes and methods of a routine's command
|
177
188
|
module CommandModule
|
178
|
-
attr_accessor :command, :matches, :nomatches, :sudo
|
189
|
+
attr_accessor :command, :matches, :nomatches, :sudo, :background
|
179
190
|
|
180
191
|
def self.descriptor_errors(c)
|
181
192
|
errors = []
|
@@ -202,6 +213,9 @@ module BlackStack
|
|
202
213
|
# validate: existis a routine with a the value c[:command].to_s on its :name key
|
203
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
|
204
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
|
205
219
|
end
|
206
220
|
|
207
221
|
# if c[:matches] exists
|
@@ -229,6 +243,12 @@ module BlackStack
|
|
229
243
|
end # each
|
230
244
|
end # if c[:matches].is_a?(Array)
|
231
245
|
end # if :matches exists
|
246
|
+
|
247
|
+
# if c[:background] exists, it must be a boolean
|
248
|
+
if c.has_key?(:background)
|
249
|
+
errors << "The value of the key :background is not a boolean" unless c[:background].is_a?(TrueClass) || c[:background].is_a?(FalseClass)
|
250
|
+
end
|
251
|
+
|
232
252
|
#
|
233
253
|
errors.uniq
|
234
254
|
end # def self.descriptor_error(h)
|
@@ -257,7 +277,12 @@ module BlackStack
|
|
257
277
|
self.nomatches << BlackStack::Deployer::NoMatch.new(m)
|
258
278
|
end
|
259
279
|
end
|
260
|
-
end
|
280
|
+
end
|
281
|
+
if h.has_key?(:background)
|
282
|
+
self.background = h[:background]
|
283
|
+
else
|
284
|
+
self.background = false
|
285
|
+
end
|
261
286
|
end # def initialize(h)
|
262
287
|
|
263
288
|
def to_hash
|
@@ -275,52 +300,84 @@ module BlackStack
|
|
275
300
|
h
|
276
301
|
end # def to_hash
|
277
302
|
|
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
|
308
|
+
# replacing parameters
|
309
|
+
ret.scan(/%[a-zA-Z0-9\_]+%/).each do |p|
|
310
|
+
if p == '%eth0_ip%' # reserved parameter
|
311
|
+
# TODO: move the method eth0_ip to the blackstack-nodes library
|
312
|
+
ret.gsub!(p, node.eth0_ip)
|
313
|
+
elsif p == '%timestamp%' # reserved parameter
|
314
|
+
# TODO: move this to a timestamp function on blackstack-core
|
315
|
+
ret.gsub!(p, Time.now.to_s.gsub(/\D/, ''))
|
316
|
+
else
|
317
|
+
if node.parameters.has_key?(p.gsub(/%/, '').to_sym)
|
318
|
+
ret.gsub!(p, node.parameters[p.gsub(/%/, '').to_sym].to_s)
|
319
|
+
else
|
320
|
+
raise "The parameter #{p} does not exist in the node descriptor #{node.parameters.to_s}"
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
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
|
325
|
+
if self.background && !BlackStack::Deployer.show_output
|
326
|
+
lines = ret.strip.lines
|
327
|
+
total = lines.size
|
328
|
+
i = 0
|
329
|
+
lines.each { |l|
|
330
|
+
i += 1
|
331
|
+
if i == total
|
332
|
+
l.gsub!(/;$/, ' > /dev/null 2>&1 &')
|
333
|
+
else
|
334
|
+
l.gsub!(/;$/, ' > /dev/null 2>&1;')
|
335
|
+
end
|
336
|
+
}
|
337
|
+
ret = lines.join("\n")
|
338
|
+
end
|
339
|
+
# apply modifications due the sudo flag
|
340
|
+
# return the code
|
341
|
+
ret = node.code(ret, self.sudo)
|
342
|
+
# return
|
343
|
+
ret
|
344
|
+
end
|
345
|
+
|
278
346
|
def run(node)
|
347
|
+
l = BlackStack::Deployer.logger
|
279
348
|
errors = []
|
280
|
-
code = self.command
|
281
349
|
output = nil
|
350
|
+
s = self.code(node)
|
282
351
|
|
283
|
-
# if
|
284
|
-
if
|
352
|
+
# if self.command is a symbol
|
353
|
+
if self.command.is_a?(Symbol)
|
285
354
|
|
286
|
-
# if
|
287
|
-
if
|
355
|
+
# if self.command is equel than :reboot
|
356
|
+
if self.command == :reboot
|
288
357
|
# call the node reboot method
|
289
358
|
node.reboot
|
290
359
|
else
|
291
360
|
# look for a routine with this name
|
292
|
-
r = BlackStack::Deployer.routines.select { |r| r.name ==
|
361
|
+
r = BlackStack::Deployer.routines.select { |r| r.name == self.command.to_s }.first
|
293
362
|
if !r.nil?
|
294
363
|
r.run(node)
|
295
364
|
else
|
296
|
-
raise "The routine #{
|
365
|
+
raise "The routine #{self.command.to_s} does not exist"
|
297
366
|
end
|
298
367
|
end
|
299
368
|
|
300
|
-
# if
|
301
|
-
elsif
|
302
|
-
# replacing parameters
|
303
|
-
code.scan(/%[a-zA-Z0-9\_]+%/).each do |p|
|
304
|
-
if p == '%eth0_ip%' # reserved parameter
|
305
|
-
# TODO: move the method eth0_ip to the blackstack-nodes library
|
306
|
-
code.gsub!(p, node.eth0_ip)
|
307
|
-
elsif p == '%timestamp%' # reserved parameter
|
308
|
-
# TODO: move this to a timestamp function on blackstack-core
|
309
|
-
code.gsub!(p, Time.now.to_s.gsub(/\D/, ''))
|
310
|
-
else
|
311
|
-
if node.parameters.has_key?(p.gsub(/%/, '').to_sym)
|
312
|
-
code.gsub!(p, node.parameters[p.gsub(/%/, '').to_sym].to_s)
|
313
|
-
else
|
314
|
-
raise "The parameter #{p} does not exist in the node descriptor #{node.parameters.to_s}"
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
369
|
+
# if self.command is a string
|
370
|
+
elsif self.command.is_a?(String)
|
318
371
|
|
319
372
|
# running the command
|
320
|
-
output
|
373
|
+
l.logs "Show command output... " if BlackStack::Deployer.show_output
|
374
|
+
l.log "\n\nCommand:\n--------\n\n#{s} " if BlackStack::Deployer.show_output
|
375
|
+
output = node.exec(s, false) # false: I already evaluated the :sudo parameter in the code method above.
|
376
|
+
l.log "\n\nOutput:\n-------\n\n#{output}" if BlackStack::Deployer.show_output
|
377
|
+
l.logf('done tracing.') if BlackStack::Deployer.show_output
|
321
378
|
|
322
379
|
# validation: at least one of the matches should happen
|
323
|
-
if self.matches.size > 0
|
380
|
+
if self.matches.size > 0 && !self.background
|
324
381
|
i = 0
|
325
382
|
self.matches.each do |m|
|
326
383
|
if m.validate(output).size == 0 # no errors
|
@@ -339,7 +396,7 @@ module BlackStack
|
|
339
396
|
# return a hash descriptor of the command result
|
340
397
|
{
|
341
398
|
:command => self.command,
|
342
|
-
:code =>
|
399
|
+
:code => s,
|
343
400
|
:output => output,
|
344
401
|
:errors => errors,
|
345
402
|
}
|
@@ -514,19 +571,19 @@ module BlackStack
|
|
514
571
|
raise "The routine #{routine_name} cannot be run on the node #{node_name}: #{errors.uniq.join(".\n")}" if errors.length > 0
|
515
572
|
|
516
573
|
# connect the node
|
517
|
-
self.logger.logs "Connecting to node #{n.name}... "
|
574
|
+
#self.logger.logs "Connecting to node #{n.name}... "
|
518
575
|
n.connect
|
519
|
-
self.logger.done
|
576
|
+
#self.logger.done
|
520
577
|
|
521
578
|
# run the routine
|
522
|
-
self.logger.logs "Running routine #{r.name}... "
|
579
|
+
#self.logger.logs "Running routine #{r.name}... "
|
523
580
|
r.run(n)
|
524
|
-
self.logger.done
|
581
|
+
#self.logger.done
|
525
582
|
|
526
583
|
# disconnect the node
|
527
|
-
self.logger.logs "Disconnecting from node #{n.name}... "
|
584
|
+
#self.logger.logs "Disconnecting from node #{n.name}... "
|
528
585
|
n.disconnect
|
529
|
-
self.logger.done
|
586
|
+
#self.logger.done
|
530
587
|
|
531
588
|
end # def
|
532
589
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackstack-deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blackstack-nodes
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.
|
19
|
+
version: 1.2.9
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.2.
|
22
|
+
version: 1.2.9
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.2.
|
29
|
+
version: 1.2.9
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.2.
|
32
|
+
version: 1.2.9
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pg
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|