Module: Madeira::Provider::EC2

Extended by:
EC2
Included in:
EC2
Defined in:
lib/madeira/provider/ec2.rb

Instance Method Summary collapse

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(options={})
  # check all required fog creds are supplied
  #TODO: #validate_creds(options)

  # connect to ec2
  #
  connect(options)

  # create an instance
  #
  server = @fog.servers.create(
    :image_id   => options[:ami],
    :flavor_id  => options[:size],
    :key_name   => options[:keypair],
    :groups     => options[:security],
    :tags       => { 'Name' => options[: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(options={})
  connect(options)
  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(options)
  # connect to ec2
  #
  connect(options)

  instances = @fog.servers.all
  instance = instances.select {|i| i.dns_name == options[:dns_name] }
  instance[0].destroy
  instance[0].reload
  while instance[0].state != "terminated" do
    print '.'
    sleep 3
    instance[0].reload
  end
  puts "#{options[:dns_name]} has been terminated."
end