Class: Pwrake::HostMap
- Inherits:
-
Hash
- Object
- Hash
- Pwrake::HostMap
- Defined in:
- lib/pwrake/option/host_map.rb
Instance Attribute Summary collapse
-
#by_id ⇒ Object
readonly
Returns the value of attribute by_id.
-
#by_name ⇒ Object
readonly
Returns the value of attribute by_name.
Class Method Summary collapse
Instance Method Summary collapse
- #group_core_weight ⇒ Object
- #group_hosts ⇒ Object
- #group_weight_sum ⇒ Object
- #host_count ⇒ Object
-
#initialize(arg = nil) ⇒ HostMap
constructor
A new instance of HostMap.
- #ipmatch_for_name(node) ⇒ Object
- #local? ⇒ Boolean
Constructor Details
#initialize(arg = nil) ⇒ HostMap
Returns a new instance of HostMap.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/pwrake/option/host_map.rb', line 97 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_id ⇒ Object (readonly)
Returns the value of attribute by_id.
124 125 126 |
# File 'lib/pwrake/option/host_map.rb', line 124 def by_id @by_id end |
#by_name ⇒ Object (readonly)
Returns the value of attribute by_name.
124 125 126 |
# File 'lib/pwrake/option/host_map.rb', line 124 def by_name @by_name end |
Class Method Details
.ipmatch_for_name(name) ⇒ Object
93 94 95 |
# File 'lib/pwrake/option/host_map.rb', line 93 def self.ipmatch_for_name(name) @@hostmap.ipmatch_for_name(name) end |
Instance Method Details
#group_core_weight ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/pwrake/option/host_map.rb', line 142 def group_core_weight a = [] self.each do |sub,list| list.each{|h| (a[h.group] ||= []) << h.weight} end a end |
#group_hosts ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/pwrake/option/host_map.rb', line 134 def group_hosts a = [] self.each do |sub,list| list.each{|h| (a[h.group] ||= []) << h.name} end a end |
#group_weight_sum ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/pwrake/option/host_map.rb', line 150 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 ⇒ Object
130 131 132 |
# File 'lib/pwrake/option/host_map.rb', line 130 def host_count @by_id.size end |
#ipmatch_for_name(node) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/pwrake/option/host_map.rb', line 158 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
126 127 128 |
# File 'lib/pwrake/option/host_map.rb', line 126 def local? @is_local end |