Class: Standup::EC2::Instance
Class Method Summary collapse
- .create(image_id, instance_type, security_groups) ⇒ Object
- .group_running(reload = false) ⇒ Object
- .list(reload = false) ⇒ Object
Instance Method Summary collapse
-
#initialize(id, info = false) ⇒ Instance
constructor
A new instance of Instance.
- #load_info ⇒ Object
- #reboot ⇒ Object
- #terminate ⇒ Object
- #wait_until(timeout = 300) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(id, info = false) ⇒ Instance
Returns a new instance of Instance.
4 5 6 7 |
# File 'lib/standup/ec2/instance.rb', line 4 def initialize id, info = false @id = id super info end |
Class Method Details
.create(image_id, instance_type, security_groups) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/standup/ec2/instance.rb', line 35 def self.create image_id, instance_type, security_groups response = api.run_instances :image_id => image_id, :key_name => Settings.aws.keypair_name, :instance_type => instance_type, :security_group => security_groups.map(&:name), :availability_zone => Settings.aws.availability_zone id = response.instancesSet.item[0].instanceId list[id] = Instance.new id end |
.group_running(reload = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/standup/ec2/instance.rb', line 24 def self.group_running reload = false result = {} SecurityGroup.list(reload).each {|name, _| result[name] = []} list(reload).each do |_, instance| instance.security_groups.each do |sg| result[sg.name] << instance end unless [:terminated, :"shutting-down"].include?(instance.state) end result end |
.list(reload = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/standup/ec2/instance.rb', line 11 def self.list reload = false if !class_variable_defined?(:@@list) || reload @@list = {} result = api.describe_instances result.reservationSet.item.each do |ritem| ritem.instancesSet.item.each do |item| @@list[item.instanceId] = new item.instanceId, build_info(ritem, item) end if ritem.instancesSet end if result.reservationSet end @@list end |
Instance Method Details
#load_info ⇒ Object
64 65 66 67 |
# File 'lib/standup/ec2/instance.rb', line 64 def load_info ritem = api.describe_instances(:instance_id => @id).reservationSet.item[0] set_info self.class.build_info(ritem, ritem.instancesSet.item[0]) end |
#reboot ⇒ Object
49 50 51 |
# File 'lib/standup/ec2/instance.rb', line 49 def reboot api.reboot_instances :instance_id => @id end |
#terminate ⇒ Object
45 46 47 |
# File 'lib/standup/ec2/instance.rb', line 45 def terminate api.terminate_instances :instance_id => @id end |
#wait_until(timeout = 300) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/standup/ec2/instance.rb', line 53 def wait_until timeout = 300 sleeping = 0 while yield(self) && sleeping < timeout sleeping += sleep 5 STDOUT.print '.' STDOUT.flush load_info end print "\n" end |