Revision df47dd3c
Added by Thomas McKay over 8 years ago
lib/hammer_cli_csv/base.rb | ||
---|---|---|
80 | 80 |
option_threads.to_i.times do |current_thread| |
81 | 81 |
start_index = ((current_thread) * lines_per_thread).to_i |
82 | 82 |
finish_index = ((current_thread + 1) * lines_per_thread).to_i |
83 |
lines = csv[start_index...finish_index].clone |
|
84 |
splits << Thread.new do |
|
85 |
lines.each do |line| |
|
86 |
if line[NAME][0] != '#' |
|
87 |
yield line |
|
83 |
finish_index = csv.length if finish_index > csv.length |
|
84 |
if start_index <= finish_index |
|
85 |
lines = csv[start_index...finish_index].clone |
|
86 |
splits << Thread.new do |
|
87 |
lines.each do |line| |
|
88 |
if line[NAME][0] != '#' |
|
89 |
yield line |
|
90 |
end |
|
88 | 91 |
end |
89 | 92 |
end |
90 | 93 |
end |
lib/hammer_cli_csv/import.rb | ||
---|---|---|
24 | 24 |
desc 'import by directory' |
25 | 25 |
|
26 | 26 |
option %w(-v --verbose), :flag, 'be verbose' |
27 |
option %w(--threads), 'THREAD_COUNT', 'Number of threads to hammer with', :default => 1 |
|
27 | 28 |
option %w(--server), 'SERVER', 'Server URL' |
28 | 29 |
option %w(-u --username), 'USERNAME', 'Username to access server' |
29 | 30 |
option %w(-p --password), 'PASSWORD', 'Password to access server' |
... | ... | |
75 | 76 |
|
76 | 77 |
args = %W( csv #{resource.sub('_', '-')} --csv-file #{options_file} ) |
77 | 78 |
args << '-v' if option_verbose? |
79 |
args += %W( --threads #{option_threads} ) |
|
78 | 80 |
hammer.run(args) |
79 | 81 |
end |
80 | 82 |
end |
lib/hammer_cli_csv/reports.rb | ||
---|---|---|
52 | 52 |
|
53 | 53 |
if !@existing_reports[name] |
54 | 54 |
print "Creating report '#{name}'..." if option_verbose? |
55 |
reported_at = line[TIME] || Time.now |
|
55 | 56 |
report = @api.resource(:reports).call(:create, { |
56 | 57 |
'host' => name, |
57 |
'reported_at' => line[TIME],
|
|
58 |
'reported_at' => reported_at,
|
|
58 | 59 |
'status' => { |
59 | 60 |
'applied' => line[APPLIED], |
60 | 61 |
'restarted' => line[RESTARTED], |
test/data/reports.csv | ||
---|---|---|
1 | 1 |
Name,Count,Time,Applied,Restarted,Failed,Failed Restarts,Skipped,Pending,Metrics |
2 |
dhcp129-000.megacorp.com,1,2009-10-22 05:14:54 UTC,1,0,0,0,0,0,"{""time"":{""config_retrieval"":""12.34""}, ""resources"":{""applied"":0, ""failed"":0, ""failed_restarts"":0, ""out_of_sync"":0, ""restarted"":0, ""scheduled"":1368, ""skipped"":1, ""total"":1450}, ""changes"":{""total"":0}}"
|
|
3 |
dhcp129-00%d.megacorp.com,3,2009-10-23 05:14:54 UTC,1,0,0,0,0,0,"{""time"":{""config_retrieval"":""12.34""}, ""resources"":{""applied"":0, ""failed"":0, ""failed_restarts"":0, ""out_of_sync"":0, ""restarted"":0, ""scheduled"":1368, ""skipped"":1, ""total"":1450}, ""changes"":{""total"":0}}"
|
|
2 |
dhcp129-000.megacorp.com,1,,1,0,0,0,0,0,"{""time"":{""config_retrieval"":12.34}, ""resources"":{""applied"":0, ""failed"":0, ""failed_restarts"":0, ""out_of_sync"":0, ""restarted"":0, ""scheduled"":1368, ""skipped"":1, ""total"":1450}, ""changes"":{""total"":0}}"
|
|
3 |
dhcp129-01%d.megacorp.com,3,2009-10-23 05:14:54 UTC,1,0,0,0,0,0,"{""time"":{""config_retrieval"":12.34}, ""resources"":{""applied"":0, ""failed"":0, ""failed_restarts"":0, ""out_of_sync"":0, ""restarted"":0, ""scheduled"":1368, ""skipped"":1, ""total"":1450}, ""changes"":{""total"":0}}"
|
|
4 | 4 |
|
Also available in: Unified diff
corrected threading
reports updated
removed debug