foreman_hooks 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e36bbbb7ffec26b6250bc5b073bea7b8237539b1
4
- data.tar.gz: 31d5746a12a9d454044e11d32c52350f616b2dd4
3
+ metadata.gz: 40ce82d00a918185af3f0e75063311cdca9c7ecb
4
+ data.tar.gz: ba63e860d91d252f31fc231a6ca16ca9f63129ca
5
5
  SHA512:
6
- metadata.gz: 96726288631740a784979242e476053d5fa9b3e2007af35e428b7a12c6fa52bae7b40c98b556c1ebd22c3dcbc9af58d611ea151d86fc28debdb10f5038e28db4
7
- data.tar.gz: a7d8dda6643da1d5e38d5fcb750410bc24ad0e775d0a1f86f677fc2b8f0699cadf4b00fe91752807a51568c8ac004d75cf58caee2d6545f209e498cb79b9f25a
6
+ metadata.gz: 6740120f31efa77b71e218bade83661697dc9aba205444f2bc04f48864d13f0b159fe74f77c76cb44c5c46228bb890f0db4997bb49969a75d9dc983c60dded52
7
+ data.tar.gz: 2a94de8cf7102c8a20c4b6ec79734a4856736ada300160dcf6793254a399cc56c9dd435a50d0256c0e39c2627e3d08a993274617c37b130c5123938ea106f0cd
data/README.md CHANGED
@@ -54,6 +54,11 @@ and to get events for a listed object (e.g. `host/managed`):
54
54
 
55
55
  ## Orchestration events
56
56
 
57
+ _Only supported on these objects:_
58
+
59
+ * _host/managed_
60
+ * _nic/\*_
61
+
57
62
  Foreman supports orchestration tasks for hosts and NICs (each network
58
63
  interface) which happen when the object is created, updated and destroyed.
59
64
  These tasks are shown to the user in the UI and if they fail, will
@@ -67,12 +72,22 @@ To add hooks to these, use these event names:
67
72
  * `update`
68
73
  * `destroy`
69
74
 
70
- Orchestration hooks can be given a priority (see below), therefore it is
71
- possible to order them before or after built-in orchestration steps (before
72
- DNS record is created for example).
75
+ Orchestration hooks can be given a priority by prefixing the filename with the
76
+ priority number, therefore it is possible to order them before or after
77
+ built-in orchestration steps (before DNS records are created for example).
78
+ Existing common priority levels are:
79
+
80
+ * _2_: Set up compute instance (create VM)
81
+ * _10_: Create DNS record
82
+ * _10_: Create DHCP reservation
83
+ * _20_: Deploy TFTP configs
84
+ * _50_: Create realm entry
85
+ * _1000_: Power up compute instance
73
86
 
74
87
  ## Rails events
75
88
 
89
+ _Supported on all object types._
90
+
76
91
  For hooks on anything apart from hosts or NICs (which support orchestration,
77
92
  as above) then the standard Rails events will be needed. These are the most
78
93
  interesting events provided:
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ # This file provides additional debug information for foreman-debug tool and is
4
+ # symlinked as /usr/share/foreman/script/foreman-debug.d/50-foreman_hooks
5
+
6
+ add_cmd "find /usr/share/foreman/config/hooks/ -type f -executable" "foreman_hooks_list"
@@ -3,7 +3,15 @@ require 'foreman_hooks'
3
3
  module ForemanHooks
4
4
  class Engine < ::Rails::Engine
5
5
  config.to_prepare do
6
- ForemanHooks.hooks.each { |klass,events| ForemanHooks.attach_hook(klass.constantize, events) }
6
+ ForemanHooks.hooks.each do |klass,events|
7
+ begin
8
+ klass_const = klass.constantize
9
+ rescue NameError => e
10
+ ForemanHooks.logger.error "foreman_hooks: unknown hook object #{klass}, check against `foreman-rake hooks:objects`"
11
+ next
12
+ end
13
+ ForemanHooks.attach_hook(klass_const, events)
14
+ end
7
15
  end
8
16
 
9
17
  initializer 'foreman_hooks.register_plugin', :before => :finisher_hook do |app|
@@ -22,7 +22,8 @@ module ForemanHooks::OrchestrationHook
22
22
  def queue_hooks(event)
23
23
  logger.debug "Observed #{event} hook on #{self}"
24
24
  unless is_a? Orchestration
25
- logger.warn "#{self.class.to_s} doesn't support orchestration, can't run orchestration hooks: use Rails events instead"
25
+ logger.error "#{self.class.to_s} doesn't support orchestration, can't run orchestration hooks: use Rails events instead"
26
+ return
26
27
  end
27
28
 
28
29
  return unless hooks = ForemanHooks.find_hooks(self.class, event)
@@ -9,7 +9,7 @@ module ForemanHooks::Util
9
9
  'host'
10
10
  when "Host::Discovered"
11
11
  'discovered_host'
12
- when "Audited::Adapters::ActiveRecord::Audit"
12
+ when "Audited::Adapters::ActiveRecord::Audit", "Audited::Audit"
13
13
  'audit'
14
14
  else
15
15
  self.class.name.downcase
data/lib/tasks/hooks.rake CHANGED
@@ -1,6 +1,7 @@
1
1
  namespace :hooks do
2
2
  desc 'Print a list of object names that can be hooked'
3
3
  task :objects => :environment do
4
+ Rails.application.config.eager_load_namespaces.each(&:eager_load!)
4
5
  puts ActiveRecord::Base.descendants.collect(&:name).collect(&:underscore).sort
5
6
  end
6
7
 
@@ -12,8 +13,18 @@ namespace :hooks do
12
13
  fail("Unknown model #{args[:object]}, run hooks:objects to get a list (#{e.message})")
13
14
  end
14
15
 
16
+ # 1. List default ActiveRecord callbacks
15
17
  events = ActiveRecord::Callbacks::CALLBACKS.map(&:to_s).reject { |e| e.start_with?('around_') }
18
+
19
+ # 2. List Foreman orchestration callbacks
16
20
  events.concat(['create', 'destroy', 'update']) if model.included_modules.include?(Orchestration)
21
+
22
+ # 3. List custom define_callbacks/define_model_callbacks
23
+ callbacks = model.methods.map { |m| $1 if m =~ /\A_([a-z]\w+)_callbacks\z/ }.compact
24
+ # ignore callbacks that are in the AR default list
25
+ callbacks.delete_if { |c| events.any? { |e| e.end_with?("_#{c}") } }
26
+ callbacks.each { |c| events.push("before_#{c}", "after_#{c}") }
27
+
17
28
  puts events.sort
18
29
  end
19
30
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Cleal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2017-02-16 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
15
- email: dcleal@redhat.com
15
+ email: dominic@cleal.org
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files:
@@ -26,6 +26,7 @@ files:
26
26
  - TODO
27
27
  - examples/hook_functions.sh
28
28
  - examples/log.sh
29
+ - extra/foreman-debug.sh
29
30
  - lib/foreman_hooks.rb
30
31
  - lib/foreman_hooks/callback_hooks.rb
31
32
  - lib/foreman_hooks/engine.rb
@@ -36,7 +37,7 @@ files:
36
37
  - test/unit/host_observer_test.rb
37
38
  homepage: http://github.com/theforeman/foreman_hooks
38
39
  licenses:
39
- - GPL-3
40
+ - GPL-3.0
40
41
  metadata: {}
41
42
  post_install_message:
42
43
  rdoc_options: []
@@ -44,17 +45,17 @@ require_paths:
44
45
  - lib
45
46
  required_ruby_version: !ruby/object:Gem::Requirement
46
47
  requirements:
47
- - - '>='
48
+ - - ">="
48
49
  - !ruby/object:Gem::Version
49
50
  version: '0'
50
51
  required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - '>='
53
+ - - ">="
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  requirements: []
56
57
  rubyforge_project:
57
- rubygems_version: 2.0.6
58
+ rubygems_version: 2.6.8
58
59
  signing_key:
59
60
  specification_version: 4
60
61
  summary: Run custom hook scripts on Foreman events