Class: Ironfan::Broker::Computers

Inherits:
Gorillib::ModelCollection
  • Object
show all
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/broker/computer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Computers

Returns a new instance of Computers.


278
279
280
281
282
283
# File 'lib/ironfan/broker/computer.rb', line 278

def initialize(*args)
  super
  options = args.pop or return
  self.clusters = options[:clusters]
  create_expected!
end

Instance Attribute Details

#clustersObject

Returns the value of attribute clusters


276
277
278
# File 'lib/ironfan/broker/computer.rb', line 276

def clusters
  @clusters
end

Instance Method Details

#aggregateObject


309
310
311
# File 'lib/ironfan/broker/computer.rb', line 309

def aggregate
  group_action(:aggregate!)
end

#build_slice_array(slice_indexes) ⇒ Object


374
375
376
377
378
# File 'lib/ironfan/broker/computer.rb', line 374

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

#correlateObject

Discovery


288
289
290
# File 'lib/ironfan/broker/computer.rb', line 288

def correlate
  values.each{|c| c.correlate }
end

#create_expected!Object

set up new computers for each server in the cluster definition


341
342
343
344
345
346
# File 'lib/ironfan/broker/computer.rb', line 341

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_copyObject


355
356
357
358
359
# File 'lib/ironfan/broker/computer.rb', line 355

def empty_copy
  result          = self.class.new
  result.clusters = self.clusters unless self.clusters.nil?
  result
end

#environmentsObject


332
333
334
# File 'lib/ironfan/broker/computer.rb', line 332

def environments
  map{|comp| comp.environment }.uniq
end

#group_action(verb) ⇒ Object


298
299
300
301
302
303
# File 'lib/ironfan/broker/computer.rb', line 298

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_namesObject

provide a human-readable list of names


381
382
383
# File 'lib/ironfan/broker/computer.rb', line 381

def joined_names
  values.map(&:name).join(", ").gsub(/, ([^,]*)$/, ' and \1')
end

#kill(options = {}) ⇒ Object

Manipulation


316
317
318
# File 'lib/ironfan/broker/computer.rb', line 316

def kill(options={})
  Ironfan.parallel(values){|cc| cc.kill(options) }
end

#launchObject


319
320
321
# File 'lib/ironfan/broker/computer.rb', line 319

def launch
  Ironfan.parallel(values){|cc| cc.launch }
end

#prepareObject


305
306
307
# File 'lib/ironfan/broker/computer.rb', line 305

def prepare
  group_action(:prepare!)
end

#save(options = {}) ⇒ Object


322
323
324
# File 'lib/ironfan/broker/computer.rb', line 322

def save(options={})
  Ironfan.parallel(values){|cc| cc.save(options) }
end

#select(&block) ⇒ Object

Return the selection inside another Computers collection


349
350
351
352
353
# File 'lib/ironfan/broker/computer.rb', line 349

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


362
363
364
365
366
367
368
369
370
371
372
# File 'lib/ironfan/broker/computer.rb', line 362

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

#startObject


325
326
327
# File 'lib/ironfan/broker/computer.rb', line 325

def start
  Ironfan.parallel(values){|cc| cc.start }
end

#stopObject


328
329
330
# File 'lib/ironfan/broker/computer.rb', line 328

def stop
  Ironfan.parallel(values){|cc| cc.stop }
end

#to_sObject


385
386
387
# File 'lib/ironfan/broker/computer.rb', line 385

def to_s
  "#{self.class}[#{values.map(&:name).join(",")}]"
end

#validateObject


292
293
294
295
296
# File 'lib/ironfan/broker/computer.rb', line 292

def validate
  computers = self
  values.each{|c| c.validate }
  values.map {|c| c.providers.values}.flatten.uniq.each {|p| p.validate computers }
end