amazon-instance 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/config/general.yml +2 -1
- data/lib/amazon-instance.rb +2 -1
- data/lib/amazon-instance/amazon-ec2.rb +16 -4
- metadata +2 -2
data/config/general.yml
CHANGED
data/lib/amazon-instance.rb
CHANGED
@@ -23,7 +23,8 @@ class AmazonInstance
|
|
23
23
|
def launch(ec2=nil)
|
24
24
|
ec2 = AmazonEC2.new(@config['access_key_id'],
|
25
25
|
@config['secret_key_id'],
|
26
|
-
URI.parse(@config['ec2_zone_url']).host
|
26
|
+
URI.parse(@config['ec2_zone_url']).host,
|
27
|
+
URI.parse(@config['elb_zone_url']).host) if ec2.nil?
|
27
28
|
|
28
29
|
group = @project[:security_group]
|
29
30
|
|
@@ -3,10 +3,13 @@ require 'socket'
|
|
3
3
|
require 'timeout'
|
4
4
|
|
5
5
|
class AmazonEC2
|
6
|
-
def initialize(access_key, secret_key,
|
6
|
+
def initialize(access_key, secret_key, ec2_server, elb_server)
|
7
7
|
@ec2 = AWS::EC2::Base.new(:access_key_id => access_key,
|
8
8
|
:secret_access_key => secret_key,
|
9
|
-
:server =>
|
9
|
+
:server => ec2_server)
|
10
|
+
@elb = AWS::ELB::Base.new(:access_key_id => access_key,
|
11
|
+
:secret_access_key => secret_key,
|
12
|
+
:server => elb_server)
|
10
13
|
end
|
11
14
|
|
12
15
|
def launch_instance(environment, config, config_dir)
|
@@ -20,9 +23,13 @@ class AmazonEC2
|
|
20
23
|
|
21
24
|
instance = @ec2.run_instances(config.to_hash)
|
22
25
|
|
23
|
-
|
26
|
+
instance_id = instance['instancesSet']['item'].first['instanceId']
|
27
|
+
|
28
|
+
if config[:load_balancer]
|
29
|
+
attach_instance_to_load_balancer(instance_id, config[:load_balancer])
|
30
|
+
end
|
24
31
|
|
25
|
-
host_by_instance(
|
32
|
+
host_by_instance(instance_id)
|
26
33
|
end
|
27
34
|
|
28
35
|
def valid_group?(group_name)
|
@@ -47,6 +54,11 @@ class AmazonEC2
|
|
47
54
|
host
|
48
55
|
end
|
49
56
|
|
57
|
+
def attach_instance_to_load_balancer(instance_id, load_balancer_name)
|
58
|
+
@elb.register_instances_with_load_balancer(:load_balancer_name => load_balancer_name,
|
59
|
+
:instances => [instance_id])
|
60
|
+
end
|
61
|
+
|
50
62
|
def sleep_till_ssh_is_open(host)
|
51
63
|
while ssh_open?(host) do
|
52
64
|
sleep(3)
|