class Blender::Discovery::Serf
Constants
- Property
Attributes
attribute[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/blender/discoveries/serf.rb, line 27 def initialize(opts = {}) @config = {} @config[:host] = opts[:host] if opts.key?(:host) @config[:port] = opts[:port] if opts.key?(:port) @config[:authkey] = opts[:authkey] if opts.key?(:authkey) @attribute = opts[:attribute] || 'name' end
Public Instance Methods
search(opts = {})
click to toggle source
# File lib/blender/discoveries/serf.rb, line 35 def search(opts = {}) opts = {} if opts.nil? tags = opts[:tags] || {} status = opts[:status] || 'alive' name = opts[:name] hosts = [] Blender::Log.debug("Using Serf agents '#{attribute}' as discovery return values") case attribute when 'name' property = Property.new('Name', lambda{|data| data}) when 'ipaddress' property = Property.new('Addr', lambda{|data| data.unpack('CCCC').join('.')}) else raise ArgumentError, "Attribute can be either 'name' or 'ipaddress', you have provided '#{attribute}'" end Blender::Log.debug("Serf memeber list call with arguments: Tags=#{tags}") Blender::Log.debug("Serf memeber list call with arguments: status=#{status}") Blender::Log.debug("Serf memeber list call with arguments: Name=#{name}") Serfx.connect(@config) do |conn| conn.members_filtered(tags, status, name).body['Members'].map do |m| hosts << property.hook.call(m[property.key]) end end hosts end