foreman_template_tasks 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1460 -0
- data/README.md +11 -0
- data/Rakefile +10 -0
- data/app/lib/actions/foreman_template_tasks/template_action.rb +58 -0
- data/app/lib/actions/foreman_template_tasks/template_export_action.rb +21 -0
- data/app/lib/actions/foreman_template_tasks/template_import_action.rb +21 -0
- data/lib/foreman_template_tasks/engine.rb +35 -0
- data/lib/foreman_template_tasks/version.rb +5 -0
- data/lib/foreman_template_tasks.rb +6 -0
- metadata +81 -0
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Foreman Template Tasks
|
2
|
+
|
3
|
+
A small [Foreman](https://theforeman.org/) plugin to add tasks for automatic template handling.
|
4
|
+
|
5
|
+
## Contributing
|
6
|
+
|
7
|
+
Bug reports and pull requests are welcome [on GitHub](https://github.com/ananace/foreman_template_tasks).
|
8
|
+
|
9
|
+
## License
|
10
|
+
|
11
|
+
The gem is available as open source under the terms of the [GPL-3.0 License](https://opensource.org/licenses/GPL-3.0).
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanTemplateTasks
|
5
|
+
class TemplateAction < Actions::Base
|
6
|
+
middleware.use Actions::Middleware::KeepCurrentUser
|
7
|
+
|
8
|
+
def plan(template_params = {})
|
9
|
+
input.update task_params: template_params
|
10
|
+
plan_self
|
11
|
+
end
|
12
|
+
|
13
|
+
def humanized_output
|
14
|
+
return unless output[:results]
|
15
|
+
|
16
|
+
exceptions = output[:results]
|
17
|
+
.reject { |r| r[:exception].nil? }
|
18
|
+
.group_by { |r| [r[:type], r[:additional_errors] || r[:exception]] }
|
19
|
+
.map do |k, v|
|
20
|
+
"#{v.size} templates#{k.first.nil? ? '' : " of type #{k.first}"} skipped: #{k.last}"
|
21
|
+
end
|
22
|
+
|
23
|
+
out = "#{humanized_action} finished, #{output[:results].select { |r| r[:exception].nil? }.count} templates handled"
|
24
|
+
if exceptions.empty?
|
25
|
+
out += '.'
|
26
|
+
else
|
27
|
+
out += ", #{output[:results].reject { |r| r[:exception].nil? }.count} skipped;"
|
28
|
+
out += "\n\n" + exceptions.join("\n")
|
29
|
+
end
|
30
|
+
out
|
31
|
+
end
|
32
|
+
|
33
|
+
def humanized_action
|
34
|
+
''
|
35
|
+
end
|
36
|
+
|
37
|
+
def task_output
|
38
|
+
(output[:results] || []).map do |r|
|
39
|
+
{
|
40
|
+
name: r[:name],
|
41
|
+
type: r[:type],
|
42
|
+
changed: r[:changed],
|
43
|
+
imported: r[:imported],
|
44
|
+
error: r[:additional_errors] || r[:exception]
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def rescue_strategy
|
50
|
+
Dynflow::Action::Rescue::Skip
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.cleanup_after
|
54
|
+
'1d'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanTemplateTasks
|
5
|
+
class TemplateExportAction < TemplateAction
|
6
|
+
|
7
|
+
def run
|
8
|
+
exporter = ForemanTemplates::TemplateExporter.new(input[:task_params])
|
9
|
+
output[:results] = exporter.export![:results].map(&:to_h)
|
10
|
+
end
|
11
|
+
|
12
|
+
def humanized_action
|
13
|
+
'Export'
|
14
|
+
end
|
15
|
+
|
16
|
+
def humanized_name
|
17
|
+
_('Export Foreman Templates')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanTemplateTasks
|
5
|
+
class TemplateImportAction < TemplateAction
|
6
|
+
|
7
|
+
def run
|
8
|
+
importer = ForemanTemplates::TemplateImporter.new(input[:task_params])
|
9
|
+
output[:results] = importer.import![:results].map(&:to_h)
|
10
|
+
end
|
11
|
+
|
12
|
+
def humanized_action
|
13
|
+
'Import'
|
14
|
+
end
|
15
|
+
|
16
|
+
def humanized_name
|
17
|
+
_('Import Foreman Templates')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dynflow'
|
4
|
+
require 'foreman-tasks'
|
5
|
+
|
6
|
+
module ForemanTemplateTasks
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
engine_name 'foreman_template_tasks'
|
9
|
+
|
10
|
+
config.autoload_paths += Dir["#{config.root}/app/lib"]
|
11
|
+
|
12
|
+
initializer 'foreman_template_tasks.register_paths' do |_app|
|
13
|
+
::ForemanTasks.dynflow.config.eager_load_paths.concat(%W[#{ForemanTemplateTasks::Engine.root}/app/lib/actions])
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer 'foreman_template_tasks.register_plugin', before: :finisher_hook do |_app|
|
17
|
+
Foreman::Plugin.register :foreman_template_tasks do
|
18
|
+
requires_foreman '>= 1.19'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
initializer 'foreman_template_tasks.dynflow_world', before: 'foreman_tasks.initialize_dynflow' do |_app|
|
23
|
+
::ForemanTasks.dynflow.require!
|
24
|
+
end
|
25
|
+
|
26
|
+
# Include concerns in this config.to_prepare block
|
27
|
+
config.to_prepare do
|
28
|
+
begin
|
29
|
+
# ::
|
30
|
+
rescue StandardError => e
|
31
|
+
Rails.logger.warn "ForemanTemplateTasks: skipping engine hook (#{e})"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman_template_tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Olofsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: foreman-tasks
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: foreman_templates
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- alexander.olofsson@liu.se
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/lib/actions/foreman_template_tasks/template_action.rb
|
52
|
+
- app/lib/actions/foreman_template_tasks/template_export_action.rb
|
53
|
+
- app/lib/actions/foreman_template_tasks/template_import_action.rb
|
54
|
+
- lib/foreman_template_tasks.rb
|
55
|
+
- lib/foreman_template_tasks/engine.rb
|
56
|
+
- lib/foreman_template_tasks/version.rb
|
57
|
+
homepage: https://github.com/ananace/foreman_template_tasks
|
58
|
+
licenses:
|
59
|
+
- GPL-3.0
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.7.9
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Foreman plug-in to automatically sync templates
|
81
|
+
test_files: []
|