foreman_template_tasks 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cadf2cfa7582574814993b1e64e062ebcf1e858c4b9a181657819ac4a98df3cc
4
- data.tar.gz: cde8f8c5e69aa42f382fa33d917000f849074ebde126060a0b5d7049d990a6c2
3
+ metadata.gz: f5eff5ce29fff335a4fa0b9dac6d560e63df62c7cd9fa5c4b840c60dbe531395
4
+ data.tar.gz: 38f816dafb3024f06a1e05e572aebc95a248f0c7180d40e172f06ead59d7625b
5
5
  SHA512:
6
- metadata.gz: 77f9954d6062cf2e9f9605e80d2ddbf593e6d0b7b1d0a0845ca615a7e3781b734ec85ded5237c77f04599fc9bc6aebc3a88bbaf3d62690ffa8874475b7d297d8
7
- data.tar.gz: c803fa133b78b112259bc8b446ea4c92ff286f781aa1d55f0f236fcfabbb76f60617847b2cd7cf96059b6bac63596e1af4020caa9d65a24bfbca5bf5c13bc8ee
6
+ metadata.gz: 6eaa275be6b95044235a179515d23f05ebcc4c8277676dcc75e050c81bb06193bbe49db38cb85ed7d6e4c7acc119be6f4472b040c205da70f3473576d4258dc8
7
+ data.tar.gz: 360d937f06920c91bbe618b231e26e345a07d49cae17851a2847b9719634d292fac00cb1d13f670eca1ecb212b3c38596f6815c38c9744370a47ebca02d332b7
@@ -3,35 +3,72 @@
3
3
  module Actions
4
4
  module ForemanTemplateTasks
5
5
  class TemplateAction < Actions::Base
6
+ include Actions::RecurringAction
7
+
6
8
  middleware.use Actions::Middleware::KeepCurrentUser
7
9
 
8
- def plan(template_params = {})
9
- input.update task_params: template_params
10
+ def delay(delay_options, context: nil, **task_params)
11
+ task_params = task_params.compact
12
+ input.update context: context
13
+ input.update task_params: task_params
14
+
15
+ super delay_options, { context: context, task_params: task_params }
16
+ end
17
+
18
+ # Rails passes hashes with keys as string by default
19
+ def plan(args = {})
20
+ _plan(args.deep_symbolize_keys)
21
+ end
22
+
23
+ def _plan(context: nil, **task_params)
24
+ input.update context: context
25
+ input.update task_params: task_params
26
+
10
27
  plan_self
11
28
  end
12
29
 
13
30
  def humanized_output
14
31
  return unless output[:results]
15
32
 
33
+ changes = output[:results]
34
+ .select { |r| (r[:imported] || r[:exported]) && r[:changed] }
35
+
16
36
  exceptions = output[:results]
17
37
  .reject { |r| r[:exception].nil? }
18
38
  .group_by { |r| [r[:type], r[:additional_errors] || r[:exception]] }
19
39
  .map do |k, v|
20
- "#{v.size} templates#{k.first.nil? ? '' : " of type #{k.first}"} skipped: #{k.last}"
40
+ "#{v.size} templates#{k.first.nil? ? '' : " of type #{k.first}"} skipped because: #{k.last}"
21
41
  end
22
42
 
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")
43
+ out = "#{humanized_action} finished, "
44
+ out += if changes.any?
45
+ "#{changes.count} templates changed"
46
+ else
47
+ location = self.class == TemplateImportAction ? 'local' : 'remote'
48
+ "no changes to #{location} templates"
49
+ end
50
+
51
+ out += if exceptions.any?
52
+ ", #{output[:results].reject { |r| r[:exception].nil? }.count} templates skipped;\n- " + exceptions.join("\n- ")
53
+ else
54
+ '.'
55
+ end
56
+
57
+ if changes.any?
58
+ out += "\n\nTemplates changed:\n- " + changes.map { |ch| "#{ch[:type].camel_case} | #{ch[:name]}" }.join("\n- ")
29
59
  end
60
+
30
61
  out
31
62
  end
32
63
 
33
64
  def humanized_action
34
- ''
65
+ raise NotImplementedError
66
+ end
67
+
68
+ def humanized_name
69
+ format N_('%<action>s Foreman Templates%<context>s'),
70
+ action: humanized_action,
71
+ context: input[:context] ? " (#{input[:context]})" : ''
35
72
  end
36
73
 
37
74
  def task_output
@@ -41,8 +78,9 @@ module Actions
41
78
  type: r[:type],
42
79
  changed: r[:changed],
43
80
  imported: r[:imported],
81
+ exported: r[:exported],
44
82
  error: r[:additional_errors] || r[:exception]
45
- }
83
+ }.compact
46
84
  end
47
85
  end
48
86
 
@@ -12,10 +12,6 @@ module Actions
12
12
  def humanized_action
13
13
  'Export'
14
14
  end
15
-
16
- def humanized_name
17
- _('Export Foreman Templates')
18
- end
19
15
  end
20
16
  end
21
17
  end
@@ -12,10 +12,6 @@ module Actions
12
12
  def humanized_action
13
13
  'Import'
14
14
  end
15
-
16
- def humanized_name
17
- _('Import Foreman Templates')
18
- end
19
15
  end
20
16
  end
21
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanTemplateTasks
4
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.2.0'.freeze
5
5
  end
@@ -0,0 +1,105 @@
1
+ require 'pp'
2
+
3
+ namespace :template_tasks do
4
+ desc 'Start a template import according to settings'
5
+ task import: :environment do
6
+ User.current = User.anonymous_admin
7
+ context = ENV['context']
8
+
9
+ r = ForemanTasks.delay Actions::ForemanTemplateTasks::TemplateImportAction,
10
+ { start_at: Time.zone.now },
11
+ {
12
+ context: context,
13
+ repo: ENV['repo'],
14
+ branch: ENV['branch'],
15
+ prefix: ENV['prefix'],
16
+ dirname: ENV['dirname'],
17
+ filter: ENV['filter'],
18
+ associate: ENV['associate'],
19
+ lock: ENV['lock']
20
+ }.compact
21
+
22
+ url = Rails.application.routes.url_helpers.foreman_tasks_task_url(r, host: SETTINGS[:fqdn])
23
+ puts "Task running at #{url}"
24
+ pp r
25
+ end
26
+
27
+ desc 'Start a template export according to settings'
28
+ task export: :environment do
29
+ User.current = User.anonymous_admin
30
+ context = ENV['context']
31
+
32
+ r = ForemanTasks.delay Actions::ForemanTemplateTasks::TemplateExportAction,
33
+ { start_at: Time.zone.now },
34
+ {
35
+ context: context,
36
+ repo: ENV['repo'],
37
+ branch: ENV['branch'],
38
+ prefix: ENV['prefix'],
39
+ dirname: ENV['dirname'],
40
+ filter: ENV['filter'],
41
+ metadata_export_mode: ENV['metadata_export_mode']
42
+ }.compact
43
+
44
+ url = Rails.application.routes.url_helpers.foreman_tasks_task_url(r, host: SETTINGS[:fqdn])
45
+ puts "Task running at #{url}"
46
+ pp r
47
+ end
48
+
49
+ namespace :import do
50
+ desc 'Schedule a recurring template import'
51
+ task schedule_recurring: :environment do
52
+ context = ENV['context']
53
+ cronline = ENV['cronline']
54
+
55
+ raise 'Need to specify a cronline' unless cronline
56
+
57
+ User.current = User.anonymous_admin
58
+ r = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
59
+
60
+ r.start Actions::ForemanTemplateTasks::TemplateImportAction,
61
+ {
62
+ context: context,
63
+ repo: ENV['repo'],
64
+ branch: ENV['branch'],
65
+ prefix: ENV['prefix'],
66
+ dirname: ENV['dirname'],
67
+ filter: ENV['filter'],
68
+ associate: ENV['associate'],
69
+ lock: ENV['lock']
70
+ }.compact
71
+
72
+ url = Rails.application.routes.url_helpers.foreman_tasks_recurring_logic_url(r, host: SETTINGS[:fqdn])
73
+ puts "Recurring logic created at #{url}"
74
+ pp r
75
+ end
76
+ end
77
+
78
+ namespace :export do
79
+ desc 'Schedule a recurring template import'
80
+ task schedule_recurring: :environment do
81
+ context = ENV['context']
82
+ cronline = ENV['cronline']
83
+
84
+ raise 'Need to specify a cronline' unless cronline
85
+
86
+ User.current = User.anonymous_admin
87
+ r = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
88
+
89
+ r.start Actions::ForemanTemplateTasks::TemplateExportAction,
90
+ {
91
+ context: context,
92
+ repo: ENV['repo'],
93
+ branch: ENV['branch'],
94
+ prefix: ENV['prefix'],
95
+ dirname: ENV['dirname'],
96
+ filter: ENV['filter'],
97
+ metadata_export_mode: ENV['metadata_export_mode']
98
+ }.compact
99
+
100
+ url = Rails.application.routes.url_helpers.foreman_tasks_recurring_logic_url(r, host: SETTINGS[:fqdn])
101
+ puts "Recurring logic created at #{url}"
102
+ pp r
103
+ end
104
+ end
105
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_template_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Olofsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-15 00:00:00.000000000 Z
11
+ date: 2019-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks
@@ -54,6 +54,7 @@ files:
54
54
  - lib/foreman_template_tasks.rb
55
55
  - lib/foreman_template_tasks/engine.rb
56
56
  - lib/foreman_template_tasks/version.rb
57
+ - lib/tasks/foreman_template_tasks.rake
57
58
  homepage: https://github.com/ananace/foreman_template_tasks
58
59
  licenses:
59
60
  - GPL-3.0
@@ -73,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
76
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.7.9
77
+ rubygems_version: 3.0.3
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Foreman plug-in to automatically sync templates