Module: Madeira::Provider::EC2
Instance Method Summary collapse
-
#create(options = {}) ⇒ Object
use fog to talk to AWS/ec2.
-
#list(options = {}) ⇒ Object
list all instances in a region.
-
#terminate(options) ⇒ Object
terminate an instance.
Instance Method Details
#create(options = {}) ⇒ Object
use fog to talk to AWS/ec2
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/madeira/provider/ec2.rb', line 8 def create(={}) # check all required fog creds are supplied #TODO: #validate_creds(options) # connect to ec2 # connect() # create an instance # server = @fog.servers.create( :image_id => [:ami], :flavor_id => [:size], :key_name => [:keypair], :groups => [:security], :tags => { 'Name' => [:name] } ) # print progress as dots whilst waiting for it to get online # server.wait_for { print "."; ready? } puts tp server, :id, {:dns_name => {:width => 65}}, :public_ip_address, :private_ip_address, :tags, :flavor_id, :key_name, :security_group_ids server end |
#list(options = {}) ⇒ Object
list all instances in a region
36 37 38 39 40 |
# File 'lib/madeira/provider/ec2.rb', line 36 def list(={}) connect() servers = @fog.servers.all tp servers, :id, :availability_zone, :state, {:dns_name => {:width => 65}}, :public_ip_address, :private_ip_address, :tags, :flavor_id, :key_name, :security_group_ids end |
#terminate(options) ⇒ Object
terminate an instance
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/madeira/provider/ec2.rb', line 44 def terminate() # connect to ec2 # connect() instances = @fog.servers.all instance = instances.select {|i| i.dns_name == [:dns_name] } instance[0].destroy instance[0].reload while instance[0].state != "terminated" do print '.' sleep 3 instance[0].reload end puts "#{[:dns_name]} has been terminated." end |