class TtlAuto::Exe

Attributes

command_templates[R]
yaml[R]

Public Class Methods

new(file, templates=nil) click to toggle source
# File lib/ttlauto/exe.rb, line 6
def initialize file, templates=nil
  @yaml = TtlAuto::Yaml.new
  @yaml.read file
  @yaml.set_categories
  unless templates.nil?
    yml = TtlAuto::Yaml.new
    @command_templates = yml.read templates
  end
end

Public Instance Methods

ping() click to toggle source
# File lib/ttlauto/exe.rb, line 22
def ping
  return_code = 0
  server_list.each do |server|
    tcp = TtlAuto::Ping.new( server )
    if tcp.scan?
      log_info "#{server[:server]}:#{server[:port]} is enable to connect"
    else
      log_error "!!! #{server[:server]}:#{server[:port]} is NOT enable to connect !!!"
      return_code = 1
    end
  end
  return_code
end
run() click to toggle source
# File lib/ttlauto/exe.rb, line 16
def run
  @yaml.records.each do |record|
    run_each_parents record
  end
end

Private Instance Methods

parents(obj) click to toggle source
# File lib/ttlauto/exe.rb, line 57
def parents obj
  if obj.class == Array
    obj
  else
    [ obj ]
  end
end
run_each_parents(record) click to toggle source
# File lib/ttlauto/exe.rb, line 50
def run_each_parents record
  @command_templates ||= {}
  parents( record['category'] ).each do |v|
    Ttl.new( record, v, @command_templates ).bind
  end
end
server_list() click to toggle source
# File lib/ttlauto/exe.rb, line 38
def server_list
  list = []
  @yaml.records.each do |record|
    list << record['define'].map{|hash| {server: hash['server'], 
                                         port: hash['protocol'],
                                         ping: (hash['ping'].nil? ? true : hash['ping'])
    } }
  end
  list.flatten!.uniq!
  list.select{|item| item[:ping] }
end