right_chimp 1.0.1 → 1.0.2
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/CHANGES +5 -0
- data/Gemfile.lock +2 -2
- data/lib/right_chimp/Chimp.rb +161 -153
- data/lib/right_chimp/exec/ExecArray.rb +8 -15
- data/lib/right_chimp/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: 5df5e7af3e88a247df0ca5f855360b6d81316b17
|
4
|
+
data.tar.gz: 45a3a90419e7f4bc8f036853f913abcfd677d6a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a9b9120dd6b2df5e2fb87e3b10c4a942bd2c987ae300b9a5f8f8500b12fb5030b665c1e83ae6cbb6b04b7c992176ad23a656f0dcb0274ab501752903b6b76d
|
7
|
+
data.tar.gz: 4fd99523738ac5a9b2f57ed65b581a74f17e1ed716cd54f0215a3d05fa9e38ebedc007269d5a2b8deebdbe84cb9b85ac4ad18977c755b5f7bac1484ea9e631fe
|
data/CHANGES
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
right_chimp (1.0.
|
4
|
+
right_chimp (1.0.2)
|
5
5
|
progressbar (~> 0.11.0)
|
6
6
|
rake (~> 0.9.2.2)
|
7
7
|
rest-client (~> 1.6.7)
|
@@ -18,7 +18,7 @@ GEM
|
|
18
18
|
i18n (0.6.1)
|
19
19
|
json (1.7.7)
|
20
20
|
mime-types (1.23)
|
21
|
-
multi_json (1.7.
|
21
|
+
multi_json (1.7.3)
|
22
22
|
net-ssh (2.6.7)
|
23
23
|
nokogiri (1.5.9)
|
24
24
|
progressbar (0.11.0)
|
data/lib/right_chimp/Chimp.rb
CHANGED
@@ -5,16 +5,16 @@
|
|
5
5
|
module Chimp
|
6
6
|
class Chimp
|
7
7
|
attr_accessor :concurrency, :delay, :retry_count, :progress, :prompt,
|
8
|
-
:quiet, :use_chimpd, :chimpd_host, :chimpd_port, :tags, :array_names,
|
8
|
+
:quiet, :use_chimpd, :chimpd_host, :chimpd_port, :tags, :array_names,
|
9
9
|
:deployment_names, :script, :servers, :ssh, :report, :interactive, :action,
|
10
10
|
:limit_start, :limit_end, :dry_run, :group, :job_id, :verify
|
11
|
-
|
11
|
+
|
12
12
|
#
|
13
13
|
# These class variables control verbosity
|
14
14
|
#
|
15
15
|
@@verbose = false
|
16
16
|
@@quiet = false
|
17
|
-
|
17
|
+
|
18
18
|
#
|
19
19
|
# Set up reasonable defaults
|
20
20
|
#
|
@@ -27,7 +27,7 @@ module Chimp
|
|
27
27
|
@verify = true
|
28
28
|
@dry_run = false
|
29
29
|
@interactive = true
|
30
|
-
|
30
|
+
|
31
31
|
#
|
32
32
|
# Job control options
|
33
33
|
#
|
@@ -35,7 +35,7 @@ module Chimp
|
|
35
35
|
@delay = 0
|
36
36
|
@retry_count = 0
|
37
37
|
@timeout = 900
|
38
|
-
|
38
|
+
|
39
39
|
@limit_start = 0
|
40
40
|
@limit_end = 0
|
41
41
|
|
@@ -46,7 +46,7 @@ module Chimp
|
|
46
46
|
@group = :default
|
47
47
|
@group_type = :parallel
|
48
48
|
@group_concurrency = 1
|
49
|
-
|
49
|
+
|
50
50
|
#
|
51
51
|
# Options for selecting objects to work on
|
52
52
|
#
|
@@ -67,7 +67,7 @@ module Chimp
|
|
67
67
|
@ignore_errors = false
|
68
68
|
|
69
69
|
@break_array_into_instances = false
|
70
|
-
@dont_check_templates_for_script = false
|
70
|
+
@dont_check_templates_for_script = false
|
71
71
|
|
72
72
|
#
|
73
73
|
# chimpd configuration
|
@@ -76,22 +76,22 @@ module Chimp
|
|
76
76
|
@chimpd_host = 'localhost'
|
77
77
|
@chimpd_port = 9055
|
78
78
|
@chimpd_wait_until_done = false
|
79
|
-
|
79
|
+
|
80
80
|
RestClient.log = nil
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
#
|
84
84
|
# Entry point for the chimp command line application
|
85
85
|
#
|
86
86
|
def run
|
87
87
|
queue = ChimpQueue.instance
|
88
|
-
|
88
|
+
|
89
89
|
parse_command_line if @interactive
|
90
90
|
check_option_validity if @interactive
|
91
91
|
disable_logging unless @@verbose
|
92
|
-
|
92
|
+
|
93
93
|
puts "chimp #{VERSION} executing..." if (@interactive and not @use_chimpd) and not @@quiet
|
94
|
-
|
94
|
+
|
95
95
|
#
|
96
96
|
# Wait for chimpd to complete tasks
|
97
97
|
#
|
@@ -113,11 +113,11 @@ module Chimp
|
|
113
113
|
# ahead and start making API calls to select the objects
|
114
114
|
# to operate upon
|
115
115
|
#
|
116
|
-
get_array_info
|
116
|
+
get_array_info
|
117
117
|
get_server_info
|
118
118
|
get_template_info
|
119
119
|
get_executable_info
|
120
|
-
|
120
|
+
|
121
121
|
#
|
122
122
|
# Optionally display the list of objects to operate on
|
123
123
|
# and prompt the user
|
@@ -125,14 +125,14 @@ module Chimp
|
|
125
125
|
if @prompt and @interactive
|
126
126
|
list_of_objects = make_human_readable_list_of_objects
|
127
127
|
confirm = (list_of_objects.size > 0 and @action != :action_none) or @action == :action_none
|
128
|
-
|
128
|
+
|
129
129
|
verify("Your command will be executed on the following:", list_of_objects, confirm)
|
130
|
-
|
130
|
+
|
131
131
|
if @servers.length >= 2 and @server_template and @executable and not @dont_check_templates_for_script
|
132
132
|
warn_if_rightscript_not_in_all_servers @servers, @server_template, @executable
|
133
133
|
end
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
#
|
137
137
|
# Load the queue with work
|
138
138
|
#
|
@@ -145,16 +145,16 @@ module Chimp
|
|
145
145
|
if @action == :action_none or queue.group[@group].size == 0
|
146
146
|
puts "No actions to perform." unless @@quiet
|
147
147
|
else
|
148
|
-
do_work
|
148
|
+
do_work
|
149
149
|
end
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
#
|
153
153
|
# Process a non-interactive chimp object command
|
154
154
|
# Used by chimpd
|
155
155
|
#
|
156
156
|
def process
|
157
|
-
get_array_info
|
157
|
+
get_array_info
|
158
158
|
get_server_info
|
159
159
|
get_template_info
|
160
160
|
get_executable_info
|
@@ -170,7 +170,7 @@ module Chimp
|
|
170
170
|
@server_template = detect_server_template(@template, @script, @servers, @array_names)
|
171
171
|
end
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
#
|
175
175
|
# Get the Executable (RightScript) info from the API
|
176
176
|
#
|
@@ -180,7 +180,7 @@ module Chimp
|
|
180
180
|
puts "Using SSH command: \"#{@ssh}\"" if @action == :action_ssh
|
181
181
|
end
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
#
|
185
185
|
# Parse command line options
|
186
186
|
#
|
@@ -221,7 +221,7 @@ module Chimp
|
|
221
221
|
[ '--timeout', '-5', GetoptLong::REQUIRED_ARGUMENT ],
|
222
222
|
[ '--noverify', '-6', GetoptLong::NO_ARGUMENT ]
|
223
223
|
)
|
224
|
-
|
224
|
+
|
225
225
|
opts.each do |opt, arg|
|
226
226
|
case opt
|
227
227
|
when '--help', '-h'
|
@@ -322,7 +322,7 @@ module Chimp
|
|
322
322
|
help
|
323
323
|
exit 1
|
324
324
|
end
|
325
|
-
|
325
|
+
|
326
326
|
#
|
327
327
|
# Before we're totally done parsing command line options,
|
328
328
|
# let's make sure that a few things make sense
|
@@ -330,9 +330,9 @@ module Chimp
|
|
330
330
|
if @group_concurrency > @concurrency
|
331
331
|
@concurrency = @group_concurrency
|
332
332
|
end
|
333
|
-
|
333
|
+
|
334
334
|
end
|
335
|
-
|
335
|
+
|
336
336
|
#
|
337
337
|
# Check for any invalid combinations of command line options
|
338
338
|
#
|
@@ -342,14 +342,14 @@ module Chimp
|
|
342
342
|
help
|
343
343
|
exit 1
|
344
344
|
end
|
345
|
-
|
345
|
+
|
346
346
|
if not @array_names.empty? and ( not @tags.empty? or not @deployment_names.empty? )
|
347
347
|
puts "ERROR: You cannot mix ServerArray queries with other types of queries."
|
348
348
|
help
|
349
349
|
exit 1
|
350
350
|
end
|
351
351
|
end
|
352
|
-
|
352
|
+
|
353
353
|
#
|
354
354
|
# Go through each of the various ways to specify servers via
|
355
355
|
# the command line (tags, deployments, etc.) and get all the info
|
@@ -360,7 +360,7 @@ module Chimp
|
|
360
360
|
@servers += get_servers_by_deployment(@deployment_names)
|
361
361
|
@servers = filter_out_non_operational_servers(@servers)
|
362
362
|
end
|
363
|
-
|
363
|
+
|
364
364
|
#
|
365
365
|
# Load up @array with server arrays to operate on
|
366
366
|
#
|
@@ -373,11 +373,11 @@ module Chimp
|
|
373
373
|
# into Servers as necessary.
|
374
374
|
#
|
375
375
|
if @break_array_into_instances
|
376
|
-
Log.debug "Breaking array into instances..."
|
376
|
+
Log.debug "Breaking array into instances..."
|
377
377
|
@servers += get_servers_by_array(@array_names)
|
378
378
|
@array_names = []
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
@array_names.each do |array_name|
|
382
382
|
Log.debug "Querying API for ServerArray \'#{array_name}\'..."
|
383
383
|
a = Ec2ServerArray.find_by(:nickname) { |n| n =~ /^#{array_name}/i }.first
|
@@ -392,7 +392,7 @@ module Chimp
|
|
392
392
|
end
|
393
393
|
end
|
394
394
|
end
|
395
|
-
|
395
|
+
|
396
396
|
#
|
397
397
|
# Get servers to operate on via a tag query
|
398
398
|
#
|
@@ -401,7 +401,7 @@ module Chimp
|
|
401
401
|
def get_servers_by_tag(tags)
|
402
402
|
return([]) unless tags.size > 0
|
403
403
|
servers = ::Tag.search("ec2_instance", tags, :match_all => @match_all)
|
404
|
-
|
404
|
+
|
405
405
|
if tags.size > 0 and servers.nil? or servers.empty?
|
406
406
|
if @ignore_errors
|
407
407
|
Log.warn "Tag query returned no results: #{tags.join(" ")}"
|
@@ -409,10 +409,10 @@ module Chimp
|
|
409
409
|
raise "Tag query returned no results: #{tags.join(" ")}"
|
410
410
|
end
|
411
411
|
end
|
412
|
-
|
412
|
+
|
413
413
|
return(servers)
|
414
414
|
end
|
415
|
-
|
415
|
+
|
416
416
|
#
|
417
417
|
# Parse deployment names and get Server objects
|
418
418
|
#
|
@@ -420,28 +420,28 @@ module Chimp
|
|
420
420
|
#
|
421
421
|
def get_servers_by_deployment(names)
|
422
422
|
servers = []
|
423
|
-
|
423
|
+
|
424
424
|
if names.size > 0
|
425
425
|
names.each do |deployment|
|
426
426
|
d = ::Deployment.find_by_nickname(deployment).first
|
427
|
-
|
427
|
+
|
428
428
|
if d == nil
|
429
429
|
if @ignore_errors
|
430
430
|
Log.warn "cannot find deployment #{deployment}"
|
431
|
-
else
|
431
|
+
else
|
432
432
|
raise "cannot find deployment #{deployment}"
|
433
433
|
end
|
434
434
|
else
|
435
435
|
d.servers_no_reload.each do |s|
|
436
436
|
servers << s
|
437
|
-
end
|
437
|
+
end
|
438
438
|
end
|
439
439
|
end
|
440
440
|
end
|
441
|
-
|
441
|
+
|
442
442
|
return(servers)
|
443
443
|
end
|
444
|
-
|
444
|
+
|
445
445
|
#
|
446
446
|
# Parse array names
|
447
447
|
#
|
@@ -452,7 +452,7 @@ module Chimp
|
|
452
452
|
if names.size > 0
|
453
453
|
names.each do |array_name|
|
454
454
|
all_arrays = ::Ec2ServerArray.find_by(:nickname) { |n| n =~ /^#{array_name}/i }
|
455
|
-
|
455
|
+
|
456
456
|
if all_arrays != nil and all_arrays.first != nil
|
457
457
|
all_arrays.first.instances.each do |s|
|
458
458
|
array_servers << s
|
@@ -460,10 +460,10 @@ module Chimp
|
|
460
460
|
end
|
461
461
|
end
|
462
462
|
end
|
463
|
-
|
463
|
+
|
464
464
|
return(array_servers)
|
465
465
|
end
|
466
|
-
|
466
|
+
|
467
467
|
#
|
468
468
|
# ServerTemplate auto-detection
|
469
469
|
#
|
@@ -471,21 +471,21 @@ module Chimp
|
|
471
471
|
#
|
472
472
|
def detect_server_template(template, script, servers, array_names_to_detect)
|
473
473
|
st = nil
|
474
|
-
|
474
|
+
|
475
475
|
#
|
476
476
|
# If we have a script name but no template, check
|
477
477
|
# each server for the script until we locate it.
|
478
478
|
#
|
479
479
|
if script and template == nil
|
480
480
|
Log.debug "getting template URI..."
|
481
|
-
|
481
|
+
|
482
482
|
if not servers.empty?
|
483
483
|
for i in (0..servers.size - 1)
|
484
|
-
|
485
|
-
template = servers[i]['server_template_href'] if not servers[i].empty?
|
484
|
+
|
485
|
+
template = servers[i]['server_template_href'] if not servers[i].empty?
|
486
486
|
break if template
|
487
487
|
end
|
488
|
-
|
488
|
+
|
489
489
|
elsif not array_names_to_detect.empty?
|
490
490
|
array_names_to_detect.each do |array_name|
|
491
491
|
a = Ec2ServerArray.find_by(:nickname) { |n| n =~ /^#{array_name}/i }.first
|
@@ -494,41 +494,41 @@ module Chimp
|
|
494
494
|
break if template
|
495
495
|
end
|
496
496
|
end
|
497
|
-
|
497
|
+
|
498
498
|
raise "Unable to locate ServerTemplate!" unless template
|
499
499
|
Log.debug "Template: #{template}"
|
500
500
|
end
|
501
|
-
|
501
|
+
|
502
502
|
#
|
503
503
|
# Now look up the ServerTemplate via the RightScale API
|
504
504
|
#
|
505
505
|
if template
|
506
|
-
Log.debug "Looking up template..."
|
507
|
-
|
506
|
+
Log.debug "Looking up template..."
|
507
|
+
|
508
508
|
if template =~ /^http/
|
509
509
|
st = ::ServerTemplate.find(template)
|
510
510
|
else
|
511
511
|
st = ::ServerTemplate.find_by_nickname(template).first
|
512
512
|
end
|
513
|
-
|
513
|
+
|
514
514
|
if st == nil
|
515
515
|
raise "No matching ServerTemplate found!"
|
516
516
|
else
|
517
|
-
Log.debug "ServerTemplate: \"#{st['nickname']}\""
|
517
|
+
Log.debug "ServerTemplate: \"#{st['nickname']}\""
|
518
518
|
end
|
519
519
|
end
|
520
|
-
|
520
|
+
|
521
521
|
return(st)
|
522
522
|
end
|
523
|
-
|
523
|
+
|
524
524
|
#
|
525
525
|
# Look up the RightScript
|
526
526
|
#
|
527
527
|
# Returns: RestConnection::Executable
|
528
528
|
#
|
529
529
|
def detect_right_script(st, script)
|
530
|
-
executable = nil
|
531
|
-
|
530
|
+
executable = nil
|
531
|
+
|
532
532
|
if script == ""
|
533
533
|
if not @interactive
|
534
534
|
puts "Error: empty --script= option is supported only in interactive mode. Exiting."
|
@@ -538,16 +538,16 @@ module Chimp
|
|
538
538
|
op_script_names = ['dummy name'] # Placeholder for #0 since we want to offer choices 1..n
|
539
539
|
op_script_hrefs = [ 'dummy href' ]
|
540
540
|
st.executables.each do |ex|
|
541
|
-
if ex.apply == "operational"
|
541
|
+
if ex.apply == "operational"
|
542
542
|
op_script_names.push( ex.name )
|
543
|
-
op_script_hrefs.push( ex.href )
|
543
|
+
op_script_hrefs.push( ex.href )
|
544
544
|
end
|
545
545
|
end
|
546
546
|
if op_script_names.length <= 1
|
547
547
|
puts "Warning: No operational scripts found on the server(s). "
|
548
|
-
puts " (Search performed on server template '#{st.nickname}')"
|
548
|
+
puts " (Search performed on server template '#{st.nickname}')"
|
549
549
|
else
|
550
|
-
puts "List of available operational scripts in the server template: ('#{st.nickname}')"
|
550
|
+
puts "List of available operational scripts in the server template: ('#{st.nickname}')"
|
551
551
|
puts "------------------------------------------------------------"
|
552
552
|
for i in 1..op_script_names.length - 1
|
553
553
|
puts " %3d. #{op_script_names[i]}" % i
|
@@ -567,7 +567,7 @@ module Chimp
|
|
567
567
|
script = op_script_hrefs[ op_script_id ]
|
568
568
|
end
|
569
569
|
end
|
570
|
-
|
570
|
+
|
571
571
|
if script
|
572
572
|
if script =~ /^http/ or script =~ /^\d+$/
|
573
573
|
if script =~ /^\d+$/
|
@@ -575,10 +575,10 @@ module Chimp
|
|
575
575
|
script = url_prefix + "/right_scripts/#{script}"
|
576
576
|
end
|
577
577
|
script_URI = script
|
578
|
-
Log.debug "Looking for script href \"#{script_URI}\""
|
579
|
-
puts
|
580
|
-
# First look up the script URI in the template.
|
581
|
-
# It *will* be found if we came here from the 'if script = ""' block
|
578
|
+
Log.debug "Looking for script href \"#{script_URI}\""
|
579
|
+
puts
|
580
|
+
# First look up the script URI in the template.
|
581
|
+
# It *will* be found if we came here from the 'if script = ""' block
|
582
582
|
script = st.executables.detect { |ex| ex.href == script }
|
583
583
|
if not script
|
584
584
|
script_obj = ::RightScript.find(script_URI)
|
@@ -586,24 +586,24 @@ module Chimp
|
|
586
586
|
script_data[ 'name' ] = script_obj.params['name']
|
587
587
|
script = ::RightScript.new({ :href => script_URI, :right_script => script_data })
|
588
588
|
end
|
589
|
-
else
|
590
|
-
Log.debug "looking for script \"#{script}\""
|
589
|
+
else
|
590
|
+
Log.debug "looking for script \"#{script}\""
|
591
591
|
script = st.executables.detect { |ex| ex.name =~ /#{script}/ }
|
592
592
|
end
|
593
|
-
|
593
|
+
|
594
594
|
if script != nil and script['right_script'] != nil
|
595
595
|
puts "RightScript: \"#{script['right_script']['name']}\"" if @interactive
|
596
596
|
else
|
597
597
|
puts "No matching RightScript found!"
|
598
598
|
raise "No matching RightScript found!"
|
599
599
|
end
|
600
|
-
|
600
|
+
|
601
601
|
executable = script
|
602
602
|
end
|
603
|
-
|
603
|
+
|
604
604
|
return(executable)
|
605
605
|
end
|
606
|
-
|
606
|
+
|
607
607
|
#
|
608
608
|
# Load up the queue with work
|
609
609
|
#
|
@@ -613,14 +613,14 @@ module Chimp
|
|
613
613
|
counter = 0
|
614
614
|
tasks = []
|
615
615
|
Log.debug "Loading queue..."
|
616
|
-
|
616
|
+
|
617
617
|
#
|
618
618
|
# Configure group
|
619
619
|
#
|
620
620
|
if not ChimpQueue[@group]
|
621
621
|
ChimpQueue.instance.create_group(@group, @group_type, @group_concurrency)
|
622
622
|
end
|
623
|
-
|
623
|
+
|
624
624
|
#
|
625
625
|
# Process ServerArray selection
|
626
626
|
#
|
@@ -628,12 +628,12 @@ module Chimp
|
|
628
628
|
if not queue_arrays.empty?
|
629
629
|
queue_arrays.each do |array|
|
630
630
|
instances = filter_out_non_operational_servers(array.instances)
|
631
|
-
|
631
|
+
|
632
632
|
if not instances
|
633
633
|
Log.error("no instances in array!")
|
634
634
|
break
|
635
635
|
end
|
636
|
-
|
636
|
+
|
637
637
|
instances.each do |array_instance|
|
638
638
|
#
|
639
639
|
# Handle limiting options
|
@@ -641,31 +641,39 @@ module Chimp
|
|
641
641
|
counter += 1
|
642
642
|
next if @limit_start.to_i > 0 and counter < @limit_start.to_i
|
643
643
|
break if @limit_end.to_i > 0 and counter > @limit_end.to_i
|
644
|
-
a = ExecArray.new(
|
644
|
+
a = ExecArray.new(
|
645
|
+
:array => array,
|
646
|
+
:server => array_instance,
|
647
|
+
:exec => queue_executable,
|
648
|
+
:inputs => @inputs,
|
649
|
+
:template => queue_template,
|
650
|
+
:verbose => @@verbose,
|
651
|
+
:quiet => @@quiet
|
652
|
+
)
|
645
653
|
a.dry_run = @dry_run
|
646
654
|
ChimpQueue.instance.push(@group, a)
|
647
655
|
end
|
648
656
|
end
|
649
657
|
end
|
650
|
-
|
658
|
+
|
651
659
|
#
|
652
660
|
# Process Server selection
|
653
661
|
#
|
654
662
|
Log.debug("Processing server selection")
|
655
|
-
|
663
|
+
|
656
664
|
queue_servers.sort! { |a,b| a['nickname'] <=> b['nickname'] }
|
657
665
|
queue_servers.each do |server|
|
658
|
-
|
666
|
+
|
659
667
|
#
|
660
668
|
# Handle limiting options
|
661
669
|
#
|
662
670
|
counter += 1
|
663
671
|
next if @limit_start.to_i > 0 and counter < @limit_start.to_i
|
664
672
|
break if @limit_end.to_i > 0 and counter > @limit_end.to_i
|
665
|
-
|
673
|
+
|
666
674
|
#
|
667
675
|
# Construct the Server object
|
668
|
-
#
|
676
|
+
#
|
669
677
|
s = ::Server.new
|
670
678
|
s.href = server['href']
|
671
679
|
s.current_instance_href = server['current_instance_href']
|
@@ -673,7 +681,7 @@ module Chimp
|
|
673
681
|
s.nickname = s.name
|
674
682
|
s.ip_address = server['ip-address'] || server['ip_address']
|
675
683
|
e = nil
|
676
|
-
|
684
|
+
|
677
685
|
if queue_executable
|
678
686
|
e = ExecRightScript.new(
|
679
687
|
:server => s,
|
@@ -683,7 +691,7 @@ module Chimp
|
|
683
691
|
:verbose => @@verbose,
|
684
692
|
:quiet => @@quiet
|
685
693
|
)
|
686
|
-
elsif @ssh
|
694
|
+
elsif @ssh
|
687
695
|
e = ExecSSH.new(
|
688
696
|
:server => s,
|
689
697
|
:ssh_user => @ssh_user,
|
@@ -708,22 +716,22 @@ module Chimp
|
|
708
716
|
e = ExecSetTags.new(:server => s, :verbose => @@verbose, :quiet => @@quiet)
|
709
717
|
e.tags = set_tags
|
710
718
|
end
|
711
|
-
|
719
|
+
|
712
720
|
if e != nil
|
713
721
|
e.dry_run = @dry_run
|
714
722
|
e.quiet = @@quiet
|
715
723
|
tasks.push(e)
|
716
724
|
end
|
717
|
-
|
725
|
+
|
718
726
|
end
|
719
|
-
|
727
|
+
|
720
728
|
return(tasks)
|
721
729
|
end
|
722
|
-
|
730
|
+
|
723
731
|
def add_to_queue(a)
|
724
732
|
a.each { |task| ChimpQueue.instance.push(@group, task) }
|
725
733
|
end
|
726
|
-
|
734
|
+
|
727
735
|
#
|
728
736
|
# Execute the user's command and provide for retrys etc.
|
729
737
|
#
|
@@ -733,18 +741,18 @@ module Chimp
|
|
733
741
|
queue.delay = delay
|
734
742
|
queue.retry_count = retry_count
|
735
743
|
total_queue_size = queue.size
|
736
|
-
|
744
|
+
|
737
745
|
puts "Executing..." unless progress or not quiet
|
738
746
|
pbar = ProgressBar.new("Executing", 100) if progress
|
739
747
|
queue.start
|
740
|
-
|
748
|
+
|
741
749
|
queue.wait_until_done(@group) do
|
742
750
|
pbar.set(((total_queue_size.to_f - queue.size.to_f)/total_queue_size.to_f*100).to_i) if progress
|
743
751
|
end
|
744
|
-
|
752
|
+
|
745
753
|
pbar.finish if progress
|
746
754
|
end
|
747
|
-
|
755
|
+
|
748
756
|
#
|
749
757
|
# Set the action
|
750
758
|
#
|
@@ -752,13 +760,13 @@ module Chimp
|
|
752
760
|
raise ArgumentError.new "Cannot reset action" unless @action == :action_none
|
753
761
|
@action = a
|
754
762
|
end
|
755
|
-
|
763
|
+
|
756
764
|
#
|
757
765
|
# Allow user to verify results and retry if necessary
|
758
766
|
#
|
759
767
|
def verify_results(group = :default)
|
760
768
|
failed_workers, results_display = get_results(group)
|
761
|
-
|
769
|
+
|
762
770
|
#
|
763
771
|
# If no workers failed, then we're done.
|
764
772
|
#
|
@@ -768,13 +776,13 @@ module Chimp
|
|
768
776
|
# Some workers failed; offer the user a chance to retry them
|
769
777
|
#
|
770
778
|
verify("The following objects failed:", results_display, false)
|
771
|
-
|
779
|
+
|
772
780
|
while true
|
773
781
|
puts "(R)etry failed jobs"
|
774
782
|
puts "(A)bort chimp run"
|
775
783
|
puts "(I)gnore errors and continue"
|
776
784
|
command = gets()
|
777
|
-
|
785
|
+
|
778
786
|
if command =~ /^a/i
|
779
787
|
puts "Aborting!"
|
780
788
|
exit 1
|
@@ -784,11 +792,11 @@ module Chimp
|
|
784
792
|
elsif command =~ /^r/i
|
785
793
|
puts "Retrying..."
|
786
794
|
ChimpQueue.instance.group[group].requeue_failed_jobs!
|
787
|
-
return false
|
795
|
+
return false
|
788
796
|
end
|
789
797
|
end
|
790
798
|
end
|
791
|
-
|
799
|
+
|
792
800
|
#
|
793
801
|
# Get the results from the QueueRunner and format them
|
794
802
|
# in a way that's easy to display to the user
|
@@ -799,7 +807,7 @@ module Chimp
|
|
799
807
|
results = queue.group[@group].results()
|
800
808
|
failed_workers = []
|
801
809
|
results_display = []
|
802
|
-
|
810
|
+
|
803
811
|
results.each do |result|
|
804
812
|
next if result == nil
|
805
813
|
|
@@ -811,20 +819,20 @@ module Chimp
|
|
811
819
|
results_display << "#{name.ljust(40)} #{message}"
|
812
820
|
end
|
813
821
|
end
|
814
|
-
|
822
|
+
|
815
823
|
return [failed_workers, results_display]
|
816
824
|
end
|
817
|
-
|
825
|
+
|
818
826
|
def print_timings
|
819
827
|
ChimpQueue.instance.group[@group].results.each do |task|
|
820
828
|
puts "Host: #{task[:host]} Type: #{task[:name]} Time: #{task[:total]} seconds"
|
821
829
|
end
|
822
830
|
end
|
823
|
-
|
831
|
+
|
824
832
|
def get_failures
|
825
833
|
return get_results(@group)
|
826
834
|
end
|
827
|
-
|
835
|
+
|
828
836
|
#
|
829
837
|
# Filter out non-operational servers
|
830
838
|
# Then add operational servers to the list of objects to display
|
@@ -834,61 +842,61 @@ module Chimp
|
|
834
842
|
servers.reject! { |s| s == nil || s['state'] != "operational" }
|
835
843
|
return(servers)
|
836
844
|
end
|
837
|
-
|
845
|
+
|
838
846
|
#
|
839
847
|
# Do work: either by submitting to chimpd
|
840
848
|
# or running it ourselves.
|
841
849
|
#
|
842
850
|
def do_work
|
843
851
|
done = false
|
844
|
-
|
852
|
+
|
845
853
|
while not done
|
846
854
|
queue_runner(@concurrency, @delay, @retry_count, @progress)
|
847
|
-
|
855
|
+
|
848
856
|
if @interactive and @verify
|
849
|
-
done = verify_results(@group)
|
857
|
+
done = verify_results(@group)
|
850
858
|
else
|
851
859
|
done = true
|
852
860
|
end
|
853
861
|
end
|
854
|
-
|
862
|
+
|
855
863
|
if not @verify
|
856
864
|
failed_workers, results_display = get_results(group)
|
857
865
|
exit 1 if failed_workers.size > 0
|
858
866
|
end
|
859
|
-
|
860
|
-
puts "chimp run complete"
|
867
|
+
|
868
|
+
puts "chimp run complete"
|
861
869
|
end
|
862
|
-
|
870
|
+
|
863
871
|
#
|
864
872
|
# Completely process a non-interactive chimp object command
|
865
873
|
#
|
866
874
|
def process
|
867
|
-
get_array_info
|
875
|
+
get_array_info
|
868
876
|
get_server_info
|
869
877
|
get_template_info
|
870
878
|
get_executable_info
|
871
879
|
return generate_jobs(@servers, @arrays, @server_template, @executable)
|
872
880
|
end
|
873
|
-
|
881
|
+
|
874
882
|
#
|
875
883
|
# Always returns 0. Used for chimpd compatibility.
|
876
884
|
#
|
877
885
|
def job_id
|
878
886
|
return 0
|
879
887
|
end
|
880
|
-
|
888
|
+
|
881
889
|
#
|
882
890
|
# Connect to chimpd and wait for the work queue to empty, and
|
883
891
|
# prompt the user if there are any errors.
|
884
892
|
#
|
885
893
|
def chimpd_wait_until_done
|
886
894
|
local_queue = ChimpQueue.instance
|
887
|
-
|
895
|
+
|
888
896
|
begin
|
889
897
|
while true
|
890
898
|
local_queue = ChimpQueue.instance
|
891
|
-
|
899
|
+
|
892
900
|
#
|
893
901
|
# load up remote chimpd jobs into the local queue
|
894
902
|
# this makes all the standard queue control methods available to us
|
@@ -896,7 +904,7 @@ module Chimp
|
|
896
904
|
retry_count = 1
|
897
905
|
while true
|
898
906
|
local_queue.reset!
|
899
|
-
|
907
|
+
|
900
908
|
begin
|
901
909
|
puts "Waiting for chimpd jobs to complete for group #{@group}..."
|
902
910
|
all = ChimpDaemonClient.retrieve_group_info(@chimpd_host, @chimpd_port, @group, :all)
|
@@ -906,25 +914,25 @@ module Chimp
|
|
906
914
|
sleep 5
|
907
915
|
retry
|
908
916
|
end
|
909
|
-
|
910
|
-
if @ignore_errors
|
917
|
+
|
918
|
+
if @ignore_errors
|
911
919
|
exit 0
|
912
920
|
else
|
913
921
|
$stderr.puts "ERROR: Group \"#{group}\" not found!"
|
914
922
|
exit 1
|
915
923
|
end
|
916
924
|
end
|
917
|
-
|
925
|
+
|
918
926
|
ChimpQueue.instance.create_group(@group)
|
919
927
|
ChimpQueue[@group].set_jobs(all)
|
920
|
-
|
928
|
+
|
921
929
|
break if ChimpQueue[@group].done?
|
922
930
|
|
923
931
|
$stdout.print "."
|
924
932
|
$stdout.flush
|
925
933
|
sleep 5
|
926
934
|
end
|
927
|
-
|
935
|
+
|
928
936
|
#
|
929
937
|
# If verify_results returns true, then ask chimpd to requeue all failed jobs.
|
930
938
|
#
|
@@ -946,17 +954,17 @@ module Chimp
|
|
946
954
|
ENV['REST_CONNECTION_LOG'] = "/dev/null"
|
947
955
|
ENV['RESTCLIENT_LOG'] = "/dev/null"
|
948
956
|
end
|
949
|
-
|
957
|
+
|
950
958
|
#
|
951
959
|
# Configure the Log object
|
952
960
|
#
|
953
961
|
def self.set_verbose(v=true, q=false)
|
954
962
|
@@verbose = v
|
955
963
|
@@quiet = q
|
956
|
-
|
964
|
+
|
957
965
|
STDOUT.sync = true
|
958
966
|
STDERR.sync = true
|
959
|
-
|
967
|
+
|
960
968
|
if @@verbose == true
|
961
969
|
Log.threshold = Logger::DEBUG
|
962
970
|
elsif @@quiet == true
|
@@ -965,22 +973,22 @@ module Chimp
|
|
965
973
|
Log.threshold = Logger::INFO
|
966
974
|
end
|
967
975
|
end
|
968
|
-
|
976
|
+
|
969
977
|
def self.verbose?
|
970
978
|
return @@verbose
|
971
979
|
end
|
972
|
-
|
980
|
+
|
973
981
|
#
|
974
982
|
# Always returns 0. Used for chimpd compatibility.
|
975
983
|
#
|
976
984
|
def job_id
|
977
985
|
return 0
|
978
986
|
end
|
979
|
-
|
987
|
+
|
980
988
|
####################################################
|
981
989
|
private
|
982
990
|
####################################################
|
983
|
-
|
991
|
+
|
984
992
|
#
|
985
993
|
# Allow the user to verify the list of servers that an
|
986
994
|
# operation will be run against.
|
@@ -988,22 +996,22 @@ module Chimp
|
|
988
996
|
def verify(message, items, confirm=true)
|
989
997
|
puts message
|
990
998
|
puts "=================================================="
|
991
|
-
|
999
|
+
|
992
1000
|
i = 0
|
993
1001
|
items.sort.each do |item|
|
994
1002
|
i += 1
|
995
1003
|
puts " %03d. #{item}" % i
|
996
1004
|
end
|
997
|
-
|
1005
|
+
|
998
1006
|
puts "=================================================="
|
999
|
-
|
1007
|
+
|
1000
1008
|
if confirm
|
1001
1009
|
puts "Press enter to confirm or ^C to exit"
|
1002
1010
|
gets
|
1003
|
-
end
|
1011
|
+
end
|
1004
1012
|
end
|
1005
1013
|
|
1006
|
-
#
|
1014
|
+
#
|
1007
1015
|
# Verify that the given rightscript_executable (the object corresponding to the script)
|
1008
1016
|
# that is associated with the server_template exists in all servers
|
1009
1017
|
# (No need to check server arrays, they must all have the same template.)
|
@@ -1017,7 +1025,7 @@ module Chimp
|
|
1017
1025
|
main_server_template = server_template
|
1018
1026
|
main_server_template_name = main_server_template.params['nickname']
|
1019
1027
|
main_server_template_href = main_server_template.params['href']
|
1020
|
-
|
1028
|
+
|
1021
1029
|
# Find which server has the specified template (the "main" template)
|
1022
1030
|
server_that_has_main_template = nil
|
1023
1031
|
for i in (0..servers.length - 1)
|
@@ -1030,18 +1038,18 @@ module Chimp
|
|
1030
1038
|
puts "internal error validating rightscript presence in all servers"
|
1031
1039
|
return
|
1032
1040
|
end
|
1033
|
-
|
1041
|
+
|
1034
1042
|
some_servers_have_different_template = false
|
1035
1043
|
num_servers_missing_rightscript = 0
|
1036
|
-
|
1044
|
+
|
1037
1045
|
for i in (0..servers.length - 1)
|
1038
1046
|
next if servers[i].empty?
|
1039
|
-
|
1047
|
+
|
1040
1048
|
this_server_template_href = servers[i]['server_template_href']
|
1041
|
-
|
1049
|
+
|
1042
1050
|
# If the server's template has the same href, this server is good
|
1043
1051
|
next if this_server_template_href == main_server_template_href
|
1044
|
-
|
1052
|
+
|
1045
1053
|
if not some_servers_have_different_template
|
1046
1054
|
some_servers_have_different_template = true
|
1047
1055
|
if not @@quiet
|
@@ -1053,7 +1061,7 @@ module Chimp
|
|
1053
1061
|
end
|
1054
1062
|
end
|
1055
1063
|
end
|
1056
|
-
|
1064
|
+
|
1057
1065
|
this_server_template = ::ServerTemplate.find(this_server_template_href)
|
1058
1066
|
next if this_server_template == nil
|
1059
1067
|
if not @@quiet
|
@@ -1063,7 +1071,7 @@ module Chimp
|
|
1063
1071
|
puts " href: '#{this_server_template.params['href']}'"
|
1064
1072
|
end
|
1065
1073
|
end
|
1066
|
-
|
1074
|
+
|
1067
1075
|
# Now check if the offending template has the rightscript in question
|
1068
1076
|
has_script = false
|
1069
1077
|
this_server_template.executables.each do |cur_script|
|
@@ -1084,7 +1092,7 @@ module Chimp
|
|
1084
1092
|
end
|
1085
1093
|
end
|
1086
1094
|
end
|
1087
|
-
if some_servers_have_different_template
|
1095
|
+
if some_servers_have_different_template
|
1088
1096
|
if num_servers_missing_rightscript == 0
|
1089
1097
|
puts "Script OK. The servers have different templates, but they all contain the script, \'#{rightscript_executable['right_script']['name']}\'"
|
1090
1098
|
else
|
@@ -1097,17 +1105,17 @@ module Chimp
|
|
1097
1105
|
end
|
1098
1106
|
puts
|
1099
1107
|
end
|
1100
|
-
|
1108
|
+
|
1101
1109
|
#
|
1102
1110
|
# Generate a human readable list of objects
|
1103
1111
|
#
|
1104
1112
|
def make_human_readable_list_of_objects
|
1105
1113
|
list_of_objects = []
|
1106
|
-
|
1114
|
+
|
1107
1115
|
if @servers
|
1108
1116
|
list_of_objects += @servers.map { |s| s['nickname'] }
|
1109
1117
|
end
|
1110
|
-
|
1118
|
+
|
1111
1119
|
if @arrays
|
1112
1120
|
@arrays.each do |a|
|
1113
1121
|
i = filter_out_non_operational_servers(a.instances)
|
@@ -1116,7 +1124,7 @@ module Chimp
|
|
1116
1124
|
end
|
1117
1125
|
return(list_of_objects)
|
1118
1126
|
end
|
1119
|
-
|
1127
|
+
|
1120
1128
|
#
|
1121
1129
|
# Print out help information
|
1122
1130
|
#
|
@@ -1127,7 +1135,7 @@ module Chimp
|
|
1127
1135
|
puts "To select servers using tags:"
|
1128
1136
|
puts " --tag=<tag> example: --tag=service:dataservice=true"
|
1129
1137
|
puts " --tag-use-and 'and' all tags when selecting servers (default)"
|
1130
|
-
puts " --tag-use-or 'or' all tags when selecting servers"
|
1138
|
+
puts " --tag-use-or 'or' all tags when selecting servers"
|
1131
1139
|
puts
|
1132
1140
|
puts "To select arrays or deployments:"
|
1133
1141
|
puts " --array=<name> array to execute upon"
|
@@ -1146,7 +1154,7 @@ module Chimp
|
|
1146
1154
|
puts " --group=<name> specify an execution group"
|
1147
1155
|
puts " --group-type=<serial|parallel> specify group execution type"
|
1148
1156
|
puts " --group-concurrency=<n> specify group concurrency, e.g. for parallel groups"
|
1149
|
-
puts
|
1157
|
+
puts
|
1150
1158
|
puts " --concurrency=<n> number of concurrent actions to perform. Default: 1"
|
1151
1159
|
puts " --delay=<seconds> delay a number of seconds between operations"
|
1152
1160
|
puts
|
@@ -1175,7 +1183,7 @@ module Chimp
|
|
1175
1183
|
puts " server_template_href, deployment_href, created_at, updated_at"
|
1176
1184
|
puts
|
1177
1185
|
end
|
1178
|
-
|
1186
|
+
|
1179
1187
|
end
|
1180
1188
|
end
|
1181
1189
|
|
@@ -6,17 +6,10 @@ module Chimp
|
|
6
6
|
def run
|
7
7
|
run_with_retry do
|
8
8
|
audit_entry = []
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
if @array.internal
|
15
|
-
audit_entry = @array.internal.run_script_on_instances(@exec, @server['href'], {})
|
16
|
-
else
|
17
|
-
audit_entry = @array.run_script_on_instances(@exec, @server['href'], {})
|
18
|
-
end
|
19
|
-
|
9
|
+
options = @inputs
|
10
|
+
|
11
|
+
audit_entry = @array.run_script_on_instances(@exec, @server['href'], options)
|
12
|
+
|
20
13
|
if audit_entry
|
21
14
|
audit_entry.each do |a|
|
22
15
|
a.wait_for_completed
|
@@ -26,18 +19,18 @@ module Chimp
|
|
26
19
|
end
|
27
20
|
end
|
28
21
|
end
|
29
|
-
|
22
|
+
|
30
23
|
def describe_work
|
31
24
|
return "ExecArray job_id=#{@job_id} script=\"#{@exec['right_script']['name']}\" server=\"#{@server['nickname']}\""
|
32
25
|
end
|
33
|
-
|
26
|
+
|
34
27
|
def info
|
35
28
|
return @exec['right_script']['name']
|
36
29
|
end
|
37
|
-
|
30
|
+
|
38
31
|
def target
|
39
32
|
return @server['nickname']
|
40
33
|
end
|
41
|
-
|
34
|
+
|
42
35
|
end
|
43
36
|
end
|
data/lib/right_chimp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_chimp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Deutsch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: progressbar
|