Parent

Included Modules

Blimpy::Box

Attributes

allowed_regions[R]
dns[RW]
flavor[RW]
fleet_id[RW]
group[RW]
image_id[RW]
internal_dns[RW]
livery[RW]
name[RW]
ports[RW]
region[R]
tags[RW]
username[RW]

Public Class Methods

from_instance_id(an_id, data) click to toggle source
# File lib/blimpy/box.rb, line 19
def self.from_instance_id(an_id, data)
  return if data[:type].nil?

  name = data[:type].to_sym
  return unless Blimpy::Boxes.const_defined? name

  klass = Blimpy::Boxes.const_get(name)

  server = klass.fog_server_for_instance(an_id, data)
  return if server.nil?

  box = klass.new(server)
  box.with_data(an_id, data)
  box
end
new(server=nil) click to toggle source
# File lib/blimpy/box.rb, line 35
def initialize(server=nil)
  @livery = nil
  @group = nil
  @name = 'Unnamed Box'
  @tags = {}
  @ports = []
  @server = server
  @fleet_id = 0
  @ssh_connected = false
  @exec_commands = true
end

Public Instance Methods

bootstrap() click to toggle source
# File lib/blimpy/box.rb, line 76
def bootstrap
  @exec_commands = false
  if @livery.nil?
    return
  end

  if @livery.respond_to? :new
    @livery = @livery.new
  end

  wait_for_sshd
  bootstrap_livery
end
bootstrap_livery() click to toggle source
# File lib/blimpy/box.rb, line 217
def bootstrap_livery
  if @livery.kind_of? Symbol
    raise Blimpy::InvalidLiveryException, 'Symbol liveries are unsupported!'
  end

  @livery.setup_on(self)
  @livery.preflight(self)
  @livery.flight(self)
  @livery.postflight(self)
end
destroy() click to toggle source
# File lib/blimpy/box.rb, line 110
def destroy
  unless @server.nil?
    predestroy
    @server.destroy
    postdestroy
    File.unlink(state_file)
  end
end
fog() click to toggle source
# File lib/blimpy/box.rb, line 251
def fog
  raise NotImplementedError, '#fog should be implemented by cloud-specific subclasses'
end
immutable_attributes() click to toggle source
# File lib/blimpy/box.rb, line 132
def immutable_attributes
  [:type]
end
online!() click to toggle source
# File lib/blimpy/box.rb, line 54
def online!
  write_state_file
end
postdestroy() click to toggle source
# File lib/blimpy/box.rb, line 119
def postdestroy
end
poststart() click to toggle source
# File lib/blimpy/box.rb, line 73
def poststart
end
predestroy() click to toggle source
# File lib/blimpy/box.rb, line 107
def predestroy
end
prestart() click to toggle source
# File lib/blimpy/box.rb, line 62
def prestart
end
provision() click to toggle source

This is just here to make things more consistent from an API perspective

# File lib/blimpy/box.rb, line 91
def provision
  bootstrap
end
region=(newRegion) click to toggle source
# File lib/blimpy/box.rb, line 47
def region=(newRegion)
  unless (@allowed_regions.nil?) || (@allowed_regions.include?(newRegion))
    raise InvalidRegionError
  end
  @region = newRegion
end
resume() click to toggle source
# File lib/blimpy/box.rb, line 101
def resume
  unless @server.nil?
    @server.start
  end
end
run_command(*args) click to toggle source
# File lib/blimpy/box.rb, line 192
def run_command(*args)
  if @exec_commands
    ::Kernel.exec(*args)
  else
    ::Kernel.system(*args)
  end
end
scp_file(filename, directory='', *args) click to toggle source
# File lib/blimpy/box.rb, line 211
def scp_file(filename, directory='', *args)
  filename = File.expand_path(filename)
  run_command('scp', '-o', 'StrictHostKeyChecking=no',
              filename, "#{username}@#{dns}:#{directory}", *args)
end
serializable_attributes() click to toggle source
# File lib/blimpy/box.rb, line 128
def serializable_attributes
  [:type, :name, :region, :dns, :internal_dns]
end
ssh_into(*args) click to toggle source
# File lib/blimpy/box.rb, line 200
def ssh_into(*args)
  # Support using #ssh_into within our own code as well to pass arguments
  # to the ssh(1) binary
  if args.empty?
    args = ARGV[2 .. -1]
  end
  run_command('ssh', '-o', 'PasswordAuthentication=no',
              '-o', 'StrictHostKeyChecking=no',
              '-l', username, dns, *args)
end
start() click to toggle source
# File lib/blimpy/box.rb, line 65
def start
  ensure_state_folder
  prestart
  @server = create_host
  poststart
  write_state_file
end
state_file() click to toggle source
# File lib/blimpy/box.rb, line 146
def state_file
  if @server.nil?
    raise Exception, "I can't make a state file without a @server!"
  end
  File.join(state_folder, "#{@server.id}.blimp")
end
stop() click to toggle source
# File lib/blimpy/box.rb, line 95
def stop
  unless @server.nil?
    @server.stop
  end
end
type() click to toggle source
# File lib/blimpy/box.rb, line 122
def type
  # We only really care about the class name as part of the Blimpy::Boxes
  # module
  self.class.to_s.split('::').last
end
validate!() click to toggle source
# File lib/blimpy/box.rb, line 58
def validate!
  raise NotImplementedError, '#validate! should be defined in a subclass of Blimpy::Box'
end
wait_for_sshd() click to toggle source
# File lib/blimpy/box.rb, line 228
def wait_for_sshd
  return if @ssh_connected
  start = Time.now.to_i
  use_exec = @exec_commands
  # Even if we are supposed to use #exec here, we wait to disable it until
  # after sshd(8) comes online
  @exec_commands = false

  until @ssh_connected
    # Run the `true` command and exit
    @ssh_connected = ssh_into('-q', 'true')

    unless @ssh_connected
      if (Time.now.to_i - start) < 60
        print '.'
        sleep 1
      end
    end
  end
  puts
  @exec_commands = use_exec
end
wait_for_state(until_state, &block) click to toggle source
# File lib/blimpy/box.rb, line 153
def wait_for_state(until_state, &block)
  if @server.nil?
    return
  end

  @server.wait_for do
    block.call
    state == until_state
  end
end
with_data(ship_id, data) click to toggle source
# File lib/blimpy/box.rb, line 165
def with_data(ship_id, data)
  data.each do |key, value|
    next if immutable_attributes.include? key.to_sym
    self.send("#{key}=", value)
  end
end
write_state_file() click to toggle source
# File lib/blimpy/box.rb, line 136
def write_state_file
  data = {}
  serializable_attributes.each do |attr|
    data[attr] = self.send(attr)
  end
  File.open(state_file, 'w') do |f|
    f.write(data.to_yaml)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.