foreman_hooks 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +12 -2
- data/lib/foreman_hooks.rb +1 -1
- data/lib/foreman_hooks/orchestration_hook.rb +6 -5
- data/lib/tasks/hooks.rake +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4dc282696356d27aa5a60add59c36a5cad8b56efff3b2d596a2d5046e9802f84
|
4
|
+
data.tar.gz: b596f8a8701a4f5bc3ced2c26ffd156cf38b113040f04db031efecf726fe3a1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db3174053c929c862debecf523943cb3f7c87dd902407579a9295f12de9f17e0d90998ad7e0d828a13303db05a9deed65181703fc4bcb40063647741561b8e51
|
7
|
+
data.tar.gz: ab116e0a5052dae4a9e0f219bedf10eb217b481a7e2f00a070eca1c736dcf196ca15cd4712f814f0bbe06bd7fa4f04ce6c03d9d1aae00ee9fc3c9dd6575823a7
|
data/README.md
CHANGED
@@ -71,12 +71,22 @@ automatically trigger a rollback of the action. A rollback is performed as
|
|
71
71
|
an opposite action (e.g. for DHCP record creation a rollback action is
|
72
72
|
destroy).
|
73
73
|
|
74
|
-
|
74
|
+
The following hooks are executed during `around_save` Rails callback:
|
75
75
|
|
76
76
|
* `create`
|
77
77
|
* `update`
|
78
|
+
|
79
|
+
The following hooks are executed during `on_destroy` Rails callback:
|
80
|
+
|
78
81
|
* `destroy`
|
79
82
|
|
83
|
+
The following hooks are executed during `after_commit` Rails callback:
|
84
|
+
|
85
|
+
* `postcreate`
|
86
|
+
* `postupdate`
|
87
|
+
|
88
|
+
The major difference between `create` and `postcreate` (or update respectively) is how late the hook is called during save operation. In the former case when a hook fails it starts rollback and operation can be still cancelled. In the latter case object was already saved and there is no way of cancelling the operation, but all referenced data should be properly loaded. The advice is to use the latter hooks as they will likely contain all the required data (e.g. nested parameters).
|
89
|
+
|
80
90
|
Orchestration hooks can be given a priority by prefixing the filename with the
|
81
91
|
priority number, therefore it is possible to order them before or after
|
82
92
|
built-in orchestration steps (before DNS records are created for example).
|
@@ -133,7 +143,7 @@ may want to ensure stdin is closed to prevent pipe buffer from filling.
|
|
133
143
|
|
134
144
|
Some arguments are available as environment variables:
|
135
145
|
|
136
|
-
Variable | Description
|
146
|
+
Variable | Description
|
137
147
|
-------- | -----------
|
138
148
|
FOREMAN_HOOKS_USER | Username of Foreman user
|
139
149
|
|
data/lib/foreman_hooks.rb
CHANGED
@@ -68,7 +68,7 @@ module ForemanHooks
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def attach_hook(klass, events)
|
71
|
-
if events.keys.detect { |event| ['create', 'update', 'destroy'].include? event }
|
71
|
+
if events.keys.detect { |event| ['create', 'update', 'destroy', 'postcreate', 'postupdate'].include? event }
|
72
72
|
unless klass.ancestors.include?(ForemanHooks::OrchestrationHook)
|
73
73
|
logger.debug "Extending #{klass} with foreman_hooks orchestration hooking support"
|
74
74
|
klass.send(:include, ForemanHooks::OrchestrationHook)
|
@@ -12,6 +12,7 @@ module ForemanHooks::OrchestrationHook
|
|
12
12
|
def queue_hooks_validate
|
13
13
|
return unless errors.empty?
|
14
14
|
queue_hooks(new_record? ? 'create' : 'update')
|
15
|
+
queue_hooks(new_record? ? 'postcreate' : 'postupdate')
|
15
16
|
end
|
16
17
|
|
17
18
|
def queue_hooks_destroy
|
@@ -33,10 +34,10 @@ module ForemanHooks::OrchestrationHook
|
|
33
34
|
hooks.each do |filename|
|
34
35
|
basename = File.basename(filename)
|
35
36
|
priority = basename =~ /^(\d+)/ ? $1 : 10000 + (counter += 1)
|
36
|
-
logger.debug "Queuing hook #{
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
logger.debug "Queuing hook #{filename} for #{self.class.to_s}##{event} at priority #{priority}"
|
38
|
+
queue_to_use = (event =~ /^post/) ? post_queue : queue
|
39
|
+
queue_to_use.create(:name => "Hook: #{filename}", :priority => priority.to_i,
|
40
|
+
:action => [HookRunner.new(filename, self, event.to_s), event.to_s == 'destroy' ? :hook_execute_del : :hook_execute_set])
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -54,7 +55,7 @@ module ForemanHooks::OrchestrationHook
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def hook_execute_set
|
57
|
-
@obj.exec_hook(@filename, @event
|
58
|
+
@obj.exec_hook(@filename, @event, *args)
|
58
59
|
end
|
59
60
|
|
60
61
|
def hook_execute_del
|
data/lib/tasks/hooks.rake
CHANGED
@@ -24,7 +24,7 @@ namespace :hooks do
|
|
24
24
|
events = ActiveRecord::Callbacks::CALLBACKS.map(&:to_s).reject { |e| e.start_with?('around_') }
|
25
25
|
|
26
26
|
# 2. List Foreman orchestration callbacks
|
27
|
-
events.concat(['create', 'destroy', 'update']) if model.included_modules.include?(Orchestration)
|
27
|
+
events.concat(['create', 'destroy', 'update', 'postcreate', 'postupdate']) if model.included_modules.include?(Orchestration)
|
28
28
|
|
29
29
|
# 3. List custom define_callbacks/define_model_callbacks
|
30
30
|
callbacks = model.methods.map { |m| $1 if m =~ /\A_([a-z]\w+)_callbacks\z/ }.compact
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominic Cleal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Plugin engine for Foreman that enables running custom hook scripts on
|
14
14
|
Foreman events
|
@@ -57,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
|
-
|
61
|
-
rubygems_version: 2.6.14.1
|
60
|
+
rubygems_version: 3.0.3
|
62
61
|
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: Run custom hook scripts on Foreman events
|