Class: EC2Instance

Inherits:
Hash
  • Object
show all
Defined in:
lib/instant_ec2.rb

Instance Method Summary collapse

Constructor Details

#initialize(h, caller = nil) ⇒ EC2Instance

Returns a new instance of EC2Instance.



10
11
12
13
14
15
# File 'lib/instant_ec2.rb', line 10

def initialize(h, caller=nil)

  @c = caller
  super().merge!(h)

end

Instance Method Details

#start(duration: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/instant_ec2.rb', line 17

def start(duration: nil)

  @c.start_instance self[:instance_id]
  
  if duration then
    
    seconds = duration.to_i * 60
    
    if @c.async then
      Thread.new{ sleep seconds; self.stop} 
    else
      sleep seconds
      self.stop
    end
  end

end

#stopObject



35
36
37
38
39
# File 'lib/instant_ec2.rb', line 35

def stop()

  @c.stop_instance self[:instance_id]

end