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.dns_name
end

#terminate(options) ⇒ Object

terminate an instance



37
38
39
40
41
42
43
44
45
# File 'lib/madeira/provider/ec2.rb', line 37

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
end