class Pwrake::HostMap
Constants
- REGEX_RANGE
Attributes
by_id[R]
by_name[R]
Public Class Methods
ipmatch_for_name(name)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 106 def self.ipmatch_for_name(name) @@hostmap.ipmatch_for_name(name) end
new(arg=nil)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 110 def initialize(arg=nil) @host_map = {} @by_id = [] @by_name = {} @is_local = false @ipmatch_for_name = {} @@hostmap = self case arg when /\.yaml$/ read_yaml(arg) when String read_host(arg) when Integer parse_hosts(["localhost #{arg}"]) when NilClass parse_hosts(["localhost 1"]) else raise ArgumentError, "arg=#{arg.inspect}" end # local check if @by_id.size == 1 if @by_id[0].local? @is_local = true end end end
Public Instance Methods
group_core_weight()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 167 def group_core_weight a = [] self.each do |sub,list| list.each{|h| (a[h.group] ||= []) << h.weight} end a end
group_hosts()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 159 def group_hosts a = [] self.each do |sub,list| list.each{|h| (a[h.group] ||= []) << h.name} end a end
group_weight_sum()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 175 def group_weight_sum a = [] self.each do |sub,list| list.each{|h| a[h.group] = (a[h.group]||0) + h.weight} end a end
host_count()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 155 def host_count @by_id.size end
ipmatch_for_name(node)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 183 def ipmatch_for_name(node) unless a = @ipmatch_for_name[node] @ipmatch_for_name[node] = a = [] ip = IPSocket.getaddress(node) @by_id.each_with_index do |h,id| a << id if h.ipaddr.include?(ip) end Log.debug "node:#{node} hosts:#{a.map{|id|@by_id[id].name}.inspect}" end a end
local?()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 151 def local? @is_local end
max_ncore()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 139 def max_ncore by_id.map{|host_info| host_info.ncore}.max end
min_ncore()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 143 def min_ncore by_id.map{|host_info| host_info.ncore}.max end
total_ncore()
click to toggle source
# File lib/pwrake/option/host_map.rb, line 147 def total_ncore by_id.inject(0){|sum,host_info| host_info.ncore + sum} end
Private Instance Methods
parse_hosts(hosts)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 211 def parse_hosts(hosts) if hosts.kind_of? Array hosts = {"localhost"=>hosts} end hosts.each do |branch, list| self[branch] = parse_list(list) end end
parse_line(info_list,line)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 230 def parse_line(info_list,line) line = $1 if /^([^#]*)#/ =~ line host, ncore, weight, group = line.split if host if REGEX_RANGE =~ host hosts = ($1..$2).map{|i| host.sub(REGEX_RANGE,i)} else hosts = [host] end hosts.each do |host| ncore &&= ncore.to_i weitht &&= weight.to_i #weight = (weight || 1).to_f group &&= group.to_i if host_info = @by_name[host] host_info.add_line(ncore,weight,group) else id = @by_id.size host_info = HostInfo.new(host,id,ncore,weight,group) @by_name[host] = host_info info_list << host_info @by_id << host_info end end end end
parse_list(line_list)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 220 def parse_list(line_list) info_list = [] line_list.each do |line| parse_line(info_list,line) end info_list end
read_host(file)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 197 def read_host(file) ary = [] File.open(file) do |f| while l = f.gets ary << l end end parse_hosts(ary) end
read_yaml(file)
click to toggle source
# File lib/pwrake/option/host_map.rb, line 207 def read_yaml(file) parse_hosts(YAML.load(open(file))[0]) end