-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEC2Wrap.rb
42 lines (33 loc) · 1.29 KB
/
EC2Wrap.rb
1
2
3
4
5
6
7
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
33
34
35
36
37
38
39
40
41
42
require 'AWS'
require 'Colorify'
class EC2Wrap
include Colorify
def provision
hash = File.open('ec2.yml') do |f| YAML.load f end
ec2 = AWS::EC2::Base.new(:access_key_id => hash["access_key"], :secret_access_key => hash["secret_key"])
# create ubuntu jaunty jakolope instance
ni = ec2.run_instances(:image_id => "ami-b31ff8da", :availability_zone => "us-east-1a", :key_name => hash["key_name"])
rid = ni["reservationId"]
instance = ec2.describe_instances(:reservationID => rid)
count = instance.reservationSet.item.count
# create volume
vol = ec2.create_volume( :availability_zone => "us-east-1a", :size => "5" )
instance = ec2.describe_instances(:reservationID => rid)
instanceid = instance.reservationSet.item[count-1].instancesSet.item[0].instanceId
#attach
flag = true
while(flag) do
begin
puts colorBlack ".."
ec2.attach_volume( :volume_id => vol.volumeId, :instance_id => instanceid, :device => '/dev/sdh')
flag = false
rescue
sleep 1
end
end
# need to re-associate our instance to figure out what the dns is
instance = ec2.describe_instances(:reservationID => rid)
dnsname = instance.reservationSet.item[count-1].instancesSet.item[0].dnsName
puts colorBlue dnsname
end
end