Class: Ironfan::Broker::Computers
- Inherits:
-
Gorillib::ModelCollection
- Object
- Gorillib::ModelCollection
- Ironfan::Broker::Computers
- Defined in:
- lib/ironfan/headers.rb,
lib/ironfan/broker/computer.rb
Instance Attribute Summary collapse
-
#clusters ⇒ Object
Returns the value of attribute clusters.
Instance Method Summary collapse
- #aggregate ⇒ Object
- #build_slice_array(slice_indexes) ⇒ Object
-
#correlate ⇒ Object
Discovery.
-
#create_expected! ⇒ Object
set up new computers for each server in the cluster definition.
- #empty_copy ⇒ Object
- #environments ⇒ Object
- #group_action(verb) ⇒ Object
-
#initialize(*args) ⇒ Computers
constructor
A new instance of Computers.
-
#joined_names ⇒ Object
provide a human-readable list of names.
-
#kill(options = {}) ⇒ Object
Manipulation.
- #launch ⇒ Object
- #prepare ⇒ Object
- #save(options = {}) ⇒ Object
-
#select(&block) ⇒ Object
Return the selection inside another Computers collection.
-
#slice(cluster_name = nil, facet_name = nil, slice_indexes = nil) ⇒ Object
Find all selected computers, as well as any bogus computers from discovery.
- #start ⇒ Object
- #stop ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(*args) ⇒ Computers
Returns a new instance of Computers.
293 294 295 296 297 298 |
# File 'lib/ironfan/broker/computer.rb', line 293 def initialize(*args) super = args.pop or return self.clusters = [:clusters] create_expected! end |
Instance Attribute Details
#clusters ⇒ Object
Returns the value of attribute clusters.
291 292 293 |
# File 'lib/ironfan/broker/computer.rb', line 291 def clusters @clusters end |
Instance Method Details
#aggregate ⇒ Object
324 325 326 |
# File 'lib/ironfan/broker/computer.rb', line 324 def aggregate group_action(:aggregate!) end |
#build_slice_array(slice_indexes) ⇒ Object
389 390 391 392 393 |
# File 'lib/ironfan/broker/computer.rb', line 389 def build_slice_array slice_indexes return [] if slice_indexes.nil? raise "Bad slice_indexes: #{slice_indexes}" if slice_indexes =~ /[^0-9\.,]/ eval("[#{slice_indexes}]").map {|idx| idx.class == Range ? idx.to_a : idx}.flatten end |
#correlate ⇒ Object
Discovery
303 304 305 |
# File 'lib/ironfan/broker/computer.rb', line 303 def correlate values.each{|c| c.correlate } end |
#create_expected! ⇒ Object
set up new computers for each server in the cluster definition
356 357 358 359 360 361 |
# File 'lib/ironfan/broker/computer.rb', line 356 def create_expected! servers = self.clusters.map{ |c| c.servers.to_a }.flatten servers.each do |server| self << Computer.new(:server => server) end unless self.clusters.nil? end |
#empty_copy ⇒ Object
370 371 372 373 374 |
# File 'lib/ironfan/broker/computer.rb', line 370 def empty_copy result = self.class.new result.clusters = self.clusters unless self.clusters.nil? result end |
#environments ⇒ Object
347 348 349 |
# File 'lib/ironfan/broker/computer.rb', line 347 def environments map{|comp| comp.environment }.uniq end |
#group_action(verb) ⇒ Object
313 314 315 316 317 318 |
# File 'lib/ironfan/broker/computer.rb', line 313 def group_action(verb) computers = self provider_keys = values.map{|c| c.chosen_providers({ :providers => :iaas })}.flatten.uniq providers = provider_keys.map{|pk| values.map{|c| c.providers[pk] } }.flatten.compact.uniq providers.each{|p| p.send(verb, computers) } end |
#joined_names ⇒ Object
provide a human-readable list of names
396 397 398 |
# File 'lib/ironfan/broker/computer.rb', line 396 def joined_names values.map(&:name).join(", ").gsub(/, ([^,]*)$/, ' and \1') end |
#kill(options = {}) ⇒ Object
Manipulation
331 332 333 |
# File 'lib/ironfan/broker/computer.rb', line 331 def kill(={}) Ironfan.parallel(values){|cc| cc.kill() } end |
#launch ⇒ Object
334 335 336 |
# File 'lib/ironfan/broker/computer.rb', line 334 def launch Ironfan.parallel(values){|cc| cc.launch } end |
#prepare ⇒ Object
320 321 322 |
# File 'lib/ironfan/broker/computer.rb', line 320 def prepare group_action(:prepare!) end |
#save(options = {}) ⇒ Object
337 338 339 |
# File 'lib/ironfan/broker/computer.rb', line 337 def save(={}) Ironfan.parallel(values){|cc| cc.save() } end |
#select(&block) ⇒ Object
Return the selection inside another Computers collection
364 365 366 367 368 |
# File 'lib/ironfan/broker/computer.rb', line 364 def select(&block) result = empty_copy values.select(&block).each{|mach| result << mach} result end |
#slice(cluster_name = nil, facet_name = nil, slice_indexes = nil) ⇒ Object
Find all selected computers, as well as any bogus computers from discovery
377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/ironfan/broker/computer.rb', line 377 def slice(cluster_name = nil, facet_name = nil, slice_indexes = nil) return self if cluster_name.nil? && facet_name.nil? && slice_indexes.nil? slice_array = build_slice_array(slice_indexes) select do |mach| mach.bogus? || ( # facet match, and index match (or no indexes specified) (mach.server.cluster_name == cluster_name) && (mach.server.facet_name == facet_name || facet_name.nil?) && (slice_array.include?(mach.server.index) || slice_indexes.nil?)) end end |
#start ⇒ Object
340 341 342 |
# File 'lib/ironfan/broker/computer.rb', line 340 def start Ironfan.parallel(values){|cc| cc.start } end |
#stop ⇒ Object
343 344 345 |
# File 'lib/ironfan/broker/computer.rb', line 343 def stop Ironfan.parallel(values){|cc| cc.stop } end |
#to_s ⇒ Object
400 401 402 |
# File 'lib/ironfan/broker/computer.rb', line 400 def to_s "#{self.class}[#{values.map(&:name).join(",")}]" end |
#validate ⇒ Object
307 308 309 310 311 |
# File 'lib/ironfan/broker/computer.rb', line 307 def validate computers = self values.each{|c| c.validate } values.map {|c| c.providers.values}.flatten.uniq.each {|p| p.validate computers } end |