lib/helpers/ec2.rb in gaptool-server-0.6.0.beta1 vs lib/helpers/ec2.rb in gaptool-server-0.6.0
- old
+ new
@@ -1,5 +1,6 @@
+require 'aws-sdk'
require 'securerandom'
# encoding: utf-8
module Gaptool
module EC2
@@ -43,18 +44,29 @@
sg.authorize_ingress :tcp, 22, *internet
return sg.id
end
def self.create_ec2_instance(ec2opts, data)
- return "i-test#{SecureRandom.hex(2)}" if ENV['DRYRUN']
- configure_ec2 data['zone'].chop
+ if ENV['DRYRUN']
+ id = "i-test#{SecureRandom.hex(2)}"
+ return {id: id,
+ hostname: "test-#{id}.#{data[:zone].chop}.compute.amazonaws.com",
+ launch_time: Time.now.to_s}
+ end
+ configure_ec2 data[:zone].chop
ec2 = AWS::EC2.new
- instance = ec2.instances.create(opts)
+ instance = ec2.instances.create(ec2opts)
instance.add_tag('Name', value: "#{data[:role]}-#{data[:env]}-#{instance.id}")
instance.add_tag('gaptool', :value => "yes")
- instance.id
+ launch_time = instance.launch_time.to_s
+ launch_time = launch_time.empty? ? Time.now.to_s : launch_time
+ {
+ id: instance.id,
+ hostname: instance.public_dns_name,
+ launch_time: launch_time
+ }
end
def self.terminate_ec2_instance(zone, id)
return if ENV['DRYRUN']
configure_ec2 zone
@@ -71,10 +83,10 @@
end
configure_ec2 zone
ec2 = AWS::EC2.new
instance = ec2.instances[id]
return {
- dns_name: instance.dns_name
+ hostname: instance.dns_name
}
end
end
end