Class | MCollective::Registration::Base |
In: |
lib/mcollective/registration/base.rb
|
Parent: | Object |
This is a base class that other registration plugins can use to handle regular announcements to the mcollective
The configuration file determines how often registration messages gets sent using the registerinterval option, the plugin runs in the background in a thread.
Register plugins that inherits base
# File lib/mcollective/registration/base.rb, line 11 11: def self.inherited(klass) 12: PluginManager << {:type => "registration_plugin", :class => klass.to_s} 13: end
# File lib/mcollective/registration/base.rb, line 69 69: def interval 70: config.registerinterval 71: end
# File lib/mcollective/registration/base.rb, line 44 44: def msg_filter 45: {"agent" => "registration"} 46: end
# File lib/mcollective/registration/base.rb, line 48 48: def msg_id(target) 49: reqid = Digest::MD5.hexdigest("#{config.identity}-#{Time.now.to_f.to_s}-#{target}") 50: end
# File lib/mcollective/registration/base.rb, line 52 52: def msg_target 53: Util.make_target("registration", :command, target_collective) 54: end
# File lib/mcollective/registration/base.rb, line 73 73: def publish(message, connection) 74: unless message 75: Log.debug("Skipping registration due to nil body") 76: else 77: target = msg_target 78: reqid = msg_id(target) 79: 80: req = PluginManager["security_plugin"].encoderequest(identity, target, message, reqid, msg_filter) 81: 82: Log.debug("Sending registration #{reqid} to #{target}") 83: 84: connection.publish(target, req) 85: end 86: end
Creates a background thread that periodically send a registration notice.
The actual registration notices comes from the ‘body’ method of the registration plugins.
# File lib/mcollective/registration/base.rb, line 19 19: def run(connection) 20: return false if interval == 0 21: 22: Thread.new do 23: loop do 24: begin 25: publish(body, connection) 26: 27: sleep interval 28: rescue Exception => e 29: Log.error("Sending registration message failed: #{e}") 30: sleep interval 31: end 32: end 33: end 34: end
# File lib/mcollective/registration/base.rb, line 56 56: def target_collective 57: main_collective = config.main_collective 58: 59: collective = config.registration_collective || main_collective 60: 61: unless config.collectives.include?(collective) 62: Log.warn("Sending registration to #{main_collective}: #{collective} is not a valid collective") 63: collective = main_collective 64: end 65: 66: return collective 67: end