module Quandl::Sandbox::Server::Instance

Constants

TIMEOUT

Attributes

instance[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/quandl/sandbox/server/instance.rb, line 42
def initialize(*args)
  # grab instance if present
  instance = args.try(:last).try(:[], :instance)
  # upwards
  super
  # assign instance if given
  self.instance = instance if instance.present?
end

Public Instance Methods

await_instance_uninterruptedly() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 68
def await_instance_uninterruptedly
  t1 = Time.now
  Quandl::Logger.debug "#{instance_id}: Waiting for instance to start up ... "
  Timeout::timeout(TIMEOUT) {
    sleep 0.5 while status == :pending
  }
  Quandl::Logger.debug "#{instance_id}: Instance started. (#{t1.elapsed_ms})"
  true
end
instance_id() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 55
def instance_id
  @instance_id ||= instance.try(:id)
end
launch!() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 63
def launch!
  self.instance = create_instance!
  add_tags_to_instance
end
private_ip_address() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 51
def private_ip_address
  @private_ip_address ||= instance.try(:private_ip_address)
end
running?() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 59
def running?
  @running ||= (status == :running) ? true : nil
end

Private Instance Methods

add_tags_to_instance() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 109
def add_tags_to_instance
  tags.each{|key, value| instance.add_tag( key.to_s, value: value.to_s ) }
end
assign_attributes_using_instance() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 101
def assign_attributes_using_instance
  self.class.attributes.each do |name|
    self.send("#{name}=", instance.send(name)) if instance.respond_to?(name)
  end
  @node_name = instance.tags['Name']
  @uid = @node_name.to_s.split('-').last
end
create_instance!() click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 91
def create_instance!
  Quandl::Sandbox::EC2.instances.create({
    image_id:             image,
    subnet_id:            subnet_id,
    availability_zone:    availability_zone,
    key_name:             key_name,
    instance_type:        instance_type 
  })
end
instance=(instance) click to toggle source
# File lib/quandl/sandbox/server/instance.rb, line 82
def instance=(instance)
  raise( ArgumentError, "instance must be of class AWS::EC2::Instance") unless instance.kind_of?(AWS::EC2::Instance)
  return false unless new_record
  # assign instance
  @instance = instance
  assign_attributes_using_instance
  self.new_record = false
end