foreman-tasks 0.7.20 → 0.8.0
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/README.md +5 -3
- data/app/controllers/foreman_tasks/concerns/parameters/triggering.rb +26 -0
- data/app/models/foreman_tasks/triggering.rb +0 -1
- data/foreman-tasks.gemspec +1 -1
- data/lib/foreman_tasks/tasks/cleanup.rake +13 -9
- data/lib/foreman_tasks/tasks/export_tasks.rake +57 -26
- data/lib/foreman_tasks/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9309d18f9110a2295d933c2464788a8cceb42161
|
4
|
+
data.tar.gz: 94bc5fd42d4c176312d80ca1a45733593a23a395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7536f877ffa338b8195477b8c2e14ca9856a0b3f125941ad1fda48383cf5c883c9061f3934e6b3ec68de7ffb706d69faa08709edc88c821139ac76765e3e5c48
|
7
|
+
data.tar.gz: f6285300dd2b63c27705c6a2fdc7f0e263e1f52faf62a4d0d40e41fa2566367df994daae4eaaebece8635b8ca0e62d9a07ab7643c04117bcc4915acbc8bfbf9a
|
data/README.md
CHANGED
@@ -178,13 +178,15 @@ override the default configuration inside the configuration
|
|
178
178
|
The `foreman_tasks:cleanup` script also accepts additional parameters
|
179
179
|
to specify the search criteria for the cleanup manually:
|
180
180
|
|
181
|
-
* `
|
181
|
+
* `TASK_SEARCH`: scoped search filter (example: 'label =
|
182
|
+
"Actions::Foreman::Host::ImportFacts"')
|
182
183
|
* `AFTER`: delete tasks created after `AFTER` period. Expected format
|
183
184
|
is a number followed by the time unit (`s`, `h`, `m`, `y`), such as
|
184
|
-
`10d` for 10 days (applicable only when the `
|
185
|
+
`10d` for 10 days (applicable only when the `TASK_SEARCH` option is
|
186
|
+
specified)
|
185
187
|
* `STATES`: comma separated list of task states to touch with the
|
186
188
|
cleanup, by default only stopped tasks are affected
|
187
|
-
(applicable only when the `
|
189
|
+
(applicable only when the `TASK_SEARCH` option is specified)
|
188
190
|
* `NOOP`: set to "true" if the task should not actuall perform the
|
189
191
|
deletion, only report the actions the script would perform
|
190
192
|
* `VERBOSE`: set to "true" for more verbose output
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ForemanTasks
|
2
|
+
module Concerns
|
3
|
+
module Parameters
|
4
|
+
module Triggering
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
include Foreman::Controller::Parameters::KeepParam
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
def triggering_params_filter
|
10
|
+
Foreman::ParameterFilter.new(::ForemanTasks::Triggering).tap do |filter|
|
11
|
+
filter.permit_by_context(:mode, :start_at, :start_before,
|
12
|
+
*::ForemanTasks::Triggering::PARAMS,
|
13
|
+
:nested => true)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def triggering_params
|
19
|
+
keep_param(params, :triggering, :days_of_week, :time, :end_time) do
|
20
|
+
self.class.triggering_params_filter.filter_params(params, parameter_filter_context, :triggering)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/foreman-tasks.gemspec
CHANGED
@@ -26,7 +26,7 @@ DESC
|
|
26
26
|
s.test_files = `git ls-files test`.split("\n")
|
27
27
|
s.extra_rdoc_files = Dir['README*', 'LICENSE']
|
28
28
|
|
29
|
-
s.add_dependency "dynflow", '~> 0.8.
|
29
|
+
s.add_dependency "dynflow", '~> 0.8.13'
|
30
30
|
s.add_dependency "sequel" # for Dynflow process persistence
|
31
31
|
s.add_dependency "sinatra" # for Dynflow web console
|
32
32
|
s.add_dependency "daemons" # for running remote executor
|
@@ -3,21 +3,21 @@ namespace :foreman_tasks do
|
|
3
3
|
desc <<DESC
|
4
4
|
Clean tasks based on filter and age. ENV variables:
|
5
5
|
|
6
|
-
*
|
7
|
-
* AFTER
|
8
|
-
* STATES
|
9
|
-
* NOOP
|
10
|
-
* VERBOSE
|
11
|
-
* BATCH_SIZE
|
6
|
+
* TASK_SEARCH : scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
|
7
|
+
* AFTER : delete tasks created after *AFTER* period. Expected format is a number followed by the time unit (s,h,m,y), such as '10d' for 10 days
|
8
|
+
* STATES : comma separated list of task states to touch with the cleanup, by default only stopped tasks are covered
|
9
|
+
* NOOP : set to "true" if the task should not actuall perform the deletion
|
10
|
+
* VERBOSE : set to "true" for more verbose output
|
11
|
+
* BATCH_SIZE : the size of batches the tasks get processed in (1000 by default)
|
12
12
|
|
13
|
-
If none of
|
13
|
+
If none of TASK_SEARCH, BEFORE, STATES is specified, the tasks will be cleaned based
|
14
14
|
configuration in settings
|
15
15
|
DESC
|
16
16
|
task :run => 'environment' do
|
17
17
|
options = {}
|
18
18
|
|
19
|
-
if ENV['
|
20
|
-
options[:filter] = ENV['
|
19
|
+
if ENV['TASK_SEARCH']
|
20
|
+
options[:filter] = ENV['TASK_SEARCH']
|
21
21
|
end
|
22
22
|
|
23
23
|
if ENV['AFTER']
|
@@ -40,6 +40,10 @@ DESC
|
|
40
40
|
options[:batch_size] = ENV['BATCH_SIZE'].to_i
|
41
41
|
end
|
42
42
|
|
43
|
+
if ENV['FILTER']
|
44
|
+
fail "FILTER has been deprecated. Please use TASK_SEARCH instead."
|
45
|
+
end
|
46
|
+
|
43
47
|
ForemanTasks::Cleaner.run(options)
|
44
48
|
end
|
45
49
|
|
@@ -2,15 +2,31 @@
|
|
2
2
|
# export_tasks.rake is a debugging tool to extract tasks from the
|
3
3
|
# current foreman instance.
|
4
4
|
#
|
5
|
-
# Run "foreman-rake export_tasks" to export tasks
|
6
|
-
# as successful.
|
7
|
-
# To export all tasks "foreman-rake export_tasks tasks=all"
|
8
|
-
# to specify the number of days of tasks to gather: days=60 (defaults to 60)
|
5
|
+
# Run "foreman-rake foreman_tasks:export_tasks" to export tasks
|
9
6
|
|
10
|
-
|
11
|
-
desc 'Export Dynflow Tasks'
|
7
|
+
require 'csv'
|
12
8
|
|
9
|
+
namespace :foreman_tasks do
|
10
|
+
desc <<DESC
|
11
|
+
Export dynflow tasks based on filter. ENV variables:
|
12
|
+
|
13
|
+
* TASK_SEARCH : scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
|
14
|
+
* TASK_FILE : file to export to
|
15
|
+
* TASK_FORMAT : format to use for the export (either html or csv)
|
16
|
+
* TASK_DAYS : number of days to go back
|
17
|
+
|
18
|
+
If TASK_SEARCH is not defined, it defaults to all tasks in the past 7 days and
|
19
|
+
all unsuccessful tasks in the past 60 days. The default TASK_FORMAT is html
|
20
|
+
which requires a tar.gz file extension.
|
21
|
+
DESC
|
13
22
|
task :export_tasks => :environment do
|
23
|
+
deprecated_options = {:tasks => "TASK_SEARCH",
|
24
|
+
:days => "TASK_DAYS",
|
25
|
+
:export => "TASK_FILE"
|
26
|
+
}
|
27
|
+
deprecated_options.each do |option, new_option|
|
28
|
+
fail "The #{option} option is deprecated. Please use #{new_option} instead" if ENV.include?(option.to_s)
|
29
|
+
end
|
14
30
|
|
15
31
|
class TaskRender
|
16
32
|
def initialize
|
@@ -218,35 +234,50 @@ namespace :foreman_tasks do
|
|
218
234
|
end
|
219
235
|
end
|
220
236
|
|
221
|
-
|
222
|
-
|
223
|
-
|
237
|
+
if ENV['TASK_SEARCH'].nil? && ENV['TASK_DAYS'].nil?
|
238
|
+
filter = "started_at > \"#{7.days.ago.to_s(:db)}\" || " \
|
239
|
+
"(result != success && started_at > \"#{60.days.ago.to_s(:db)})\""
|
224
240
|
else
|
225
|
-
|
241
|
+
filter = ENV['TASK_SEARCH'] || ''
|
226
242
|
end
|
227
243
|
|
228
|
-
days = ENV['
|
229
|
-
|
230
|
-
|
244
|
+
if (days = ENV['TASK_DAYS'])
|
245
|
+
filter += " && " unless filter == ''
|
246
|
+
filter += "started_at > \"#{days.to_i.days.ago.to_s(:db)}\""
|
247
|
+
end
|
231
248
|
|
232
|
-
|
233
|
-
|
234
|
-
PageHelper.copy_assets(tmp_dir)
|
249
|
+
format = ENV['TASK_FORMAT'] || 'html'
|
250
|
+
export_filename = ENV['TASK_FILE'] || "/tmp/task-export-#{DateTime.now.to_i}.#{format == 'csv' ? 'csv' : 'tar.gz'}"
|
235
251
|
|
252
|
+
tasks = ForemanTasks::Task.search_for(filter)
|
236
253
|
|
237
|
-
|
238
|
-
|
239
|
-
|
254
|
+
puts _("Gathering #{tasks.count} tasks.")
|
255
|
+
if format == 'html'
|
256
|
+
Dir.mktmpdir('task-export') do |tmp_dir|
|
257
|
+
PageHelper.copy_assets(tmp_dir)
|
240
258
|
|
241
|
-
tasks.all.each do |task|
|
242
|
-
File.open(File.join(tmp_dir, "#{task.id}.html"), 'w') {|file| file.write(PageHelper.pagify(renderer.render_task(task)))}
|
243
|
-
puts "#{count}/#{total}"
|
244
|
-
count += 1
|
245
|
-
end
|
246
259
|
|
247
|
-
|
260
|
+
renderer = TaskRender.new
|
261
|
+
total = tasks.count
|
248
262
|
|
249
|
-
|
263
|
+
tasks.each_with_index do |task, count|
|
264
|
+
File.open(File.join(tmp_dir, "#{task.id}.html"), 'w') {|file| file.write(PageHelper.pagify(renderer.render_task(task)))}
|
265
|
+
puts "#{count + 1}/#{total}"
|
266
|
+
count += 1
|
267
|
+
end
|
268
|
+
|
269
|
+
File.open(File.join(tmp_dir, "index.html"), 'w') {|file| file.write(PageHelper.pagify(PageHelper.generate_index(tasks)))}
|
270
|
+
|
271
|
+
sh("tar cvzf #{export_filename} #{tmp_dir} > /dev/null")
|
272
|
+
end
|
273
|
+
elsif format == 'csv'
|
274
|
+
CSV.open(export_filename, 'wb') do |csv|
|
275
|
+
csv << ['id', 'state', 'type', 'label', 'result', 'parent_task_id', 'started_at', 'ended_at']
|
276
|
+
tasks.each do |task|
|
277
|
+
csv << [task.id, task.state, task.type, task.label, task.result,
|
278
|
+
task.parent_task_id, task.started_at, task.ended_at]
|
279
|
+
end
|
280
|
+
end
|
250
281
|
end
|
251
282
|
|
252
283
|
puts "Created #{export_filename}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dynflow
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.
|
19
|
+
version: 0.8.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.
|
26
|
+
version: 0.8.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sequel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- app/controllers/foreman_tasks/api/tasks_controller.rb
|
106
106
|
- app/controllers/foreman_tasks/concerns/environments_extension.rb
|
107
107
|
- app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb
|
108
|
+
- app/controllers/foreman_tasks/concerns/parameters/triggering.rb
|
108
109
|
- app/controllers/foreman_tasks/recurring_logics_controller.rb
|
109
110
|
- app/controllers/foreman_tasks/tasks_controller.rb
|
110
111
|
- app/helpers/foreman_tasks/foreman_tasks_helper.rb
|