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.



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

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.



291
292
293
# File 'lib/ironfan/broker/computer.rb', line 291

def clusters
  @clusters
end

Instance Method Details

#aggregateObject



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

#correlateObject

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_copyObject



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

#environmentsObject



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_namesObject

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(options={})
  Ironfan.parallel(values){|cc| cc.kill(options) }
end

#launchObject



334
335
336
# File 'lib/ironfan/broker/computer.rb', line 334

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

#prepareObject



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(options={})
  Ironfan.parallel(values){|cc| cc.save(options) }
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

#startObject



340
341
342
# File 'lib/ironfan/broker/computer.rb', line 340

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

#stopObject



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

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

#to_sObject



400
401
402
# File 'lib/ironfan/broker/computer.rb', line 400

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

#validateObject



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