Parent

Included Modules

Blimpy::Fleet

Attributes

id[R]
ships[R]

Public Class Methods

new() click to toggle source
# File lib/blimpy/fleet.rb, line 11
def initialize
  @ships = []
  @id = Time.now.utc.to_i
  @airborn = false
end

Public Instance Methods

add(box_type, &block) click to toggle source
# File lib/blimpy/fleet.rb, line 21
def add(box_type, &block)
  unless valid_types.include? box_type
    raise Blimpy::InvalidShipException
  end
  if block.nil?
    return false
  end

  box = nil
  if box_type == :aws
    box = Blimpy::Boxes::AWS.new
  end
  if box_type == :openstack
    box = Blimpy::Boxes::OpenStack.new
  end

  if box.nil?
    return false
  end
  box.fleet_id = @id
  @ships << box
  block.call(box)
end
animate() click to toggle source
# File lib/blimpy/fleet.rb, line 71
def animate
  buffer ="""
        _..--=--..._
      .-'            '-.  .-.
    /.'              '.\\/  /
    |=-  B L I M P Y   -=| (
    \\'.              .'/\\  \\
      '-.,_____ _____.-'  '-'
          [_____]=+ ~ ~"""
  frames = [
    'x~   ',
    'x ~  ',
    '+~ ~ ',
    '+ ~ ~',
    '+  ~ ',
    'x   ~',
  ]

  print buffer
  $stdout.flush
  until @airborn do
    frames.each do |frame|
      # Reset every frame
      5.times { print "\b" }
      print frame
      $stdout.flush
      sleep 0.2
    end
  end
end
destroy() click to toggle source
# File lib/blimpy/fleet.rb, line 162
def destroy
  members.each do |instance_id, instance_data|
    box = Blimpy::Box.from_instance_id(instance_id, instance_data)
    box.destroy
  end

  if File.exists? state_file
    File.unlink(state_file)
  end
end
members() click to toggle source
# File lib/blimpy/fleet.rb, line 134
def members
  instances = []
  Dir["#{Dir.pwd}/.blimpy.d/*.blimp"].each do |d|
    filename = File.basename(d)
    instance_id = filename.split('.blimp').first
    instance_data = YAML.load_file(d)
    instances << [instance_id, instance_data]
  end
  instances
end
resume(instances) click to toggle source
# File lib/blimpy/fleet.rb, line 55
def resume(instances)
  boxes = []
  print '>> Resuming: '
  instances.each do |instance_id, instance_data|
    print "#{instance_data[:name]},"
    box = Blimpy::Box.from_instance_id(instance_id, instance_data)
    box.resume
    boxes << box
  end

  boxes.each do |box|
    box.wait_for_state('running') { print '.' }
  end
  puts
end
save!() click to toggle source
# File lib/blimpy/fleet.rb, line 49
def save!
  File.open(state_file, 'w') do |f|
    f.write("id=#{id}\n")
  end
end
start() click to toggle source
# File lib/blimpy/fleet.rb, line 102
def start
  instances = members
  unless instances.empty?
    return resume(instances)
  end

  # Make sure all our ships are valid first!
  @ships.each do |host|
    host.validate!
  end

  Thread.new do
    animate
  end

  @ships.each do |host|
    host.start
  end

  @ships.each do |host|
    host.wait_for_state('running') {  }
    @airborn = true
    print "\n"
    puts ">> #{host.name} online at: #{host.dns}"
    host.online!
    host.bootstrap
    puts
  end

  save!
end
state_file() click to toggle source
# File lib/blimpy/fleet.rb, line 45
def state_file
  File.join(state_folder, 'manifest')
end
stop() click to toggle source
# File lib/blimpy/fleet.rb, line 145
def stop
  print '>> Stopping: '
  boxes = []

  members.each do |instance_id, instance_data|
    box = Blimpy::Box.from_instance_id(instance_id, instance_data)
    print "#{instance_data[:name]},"
    box.stop
    boxes << box
  end

  boxes.each do |box|
    box.wait_for_state('stopped')  { print '.' }
  end
  puts
end
valid_types() click to toggle source
# File lib/blimpy/fleet.rb, line 17
def valid_types
  [:aws, :openstack]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.