Class: Pwrake::HostMap

Inherits:
Hash
  • Object
show all
Defined in:
lib/pwrake/option/host_map.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ HostMap

Returns a new instance of HostMap.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# 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

Instance Attribute Details

#by_idObject (readonly)

Returns the value of attribute by_id.



137
138
139
# File 'lib/pwrake/option/host_map.rb', line 137

def by_id
  @by_id
end

#by_nameObject (readonly)

Returns the value of attribute by_name.



137
138
139
# File 'lib/pwrake/option/host_map.rb', line 137

def by_name
  @by_name
end

Class Method Details

.ipmatch_for_name(name) ⇒ Object



106
107
108
# File 'lib/pwrake/option/host_map.rb', line 106

def self.ipmatch_for_name(name)
  @@hostmap.ipmatch_for_name(name)
end

Instance Method Details

#group_core_weightObject



167
168
169
170
171
172
173
# 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_hostsObject



159
160
161
162
163
164
165
# 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_sumObject



175
176
177
178
179
180
181
# 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_countObject



155
156
157
# File 'lib/pwrake/option/host_map.rb', line 155

def host_count
  @by_id.size
end

#ipmatch_for_name(node) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
# 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?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/pwrake/option/host_map.rb', line 151

def local?
  @is_local
end

#max_ncoreObject



139
140
141
# File 'lib/pwrake/option/host_map.rb', line 139

def max_ncore
  by_id.map{|host_info| host_info.ncore}.max
end

#min_ncoreObject



143
144
145
# File 'lib/pwrake/option/host_map.rb', line 143

def min_ncore
  by_id.map{|host_info| host_info.ncore}.max
end

#total_ncoreObject



147
148
149
# File 'lib/pwrake/option/host_map.rb', line 147

def total_ncore
  by_id.inject(0){|sum,host_info| host_info.ncore + sum}
end