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.
@@ -1,3 +1,4 @@
1
1
  access_key_id: YOUR_ACCESS_KEY
2
2
  secret_key_id: YOUR_SECRET_KEY
3
- ec2_zone_url: https://eu-west-1.ec2.amazonaws.com
3
+ ec2_zone_url: https://eu-west-1.ec2.amazonaws.com
4
+ elb_zone_url: http://elasticloadbalancing.eu-west-1.amazonaws.com
@@ -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) if ec2.nil?
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, server)
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 => 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
- instanceId = instance['instancesSet']['item'].first['instanceId']
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(instanceId)
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)
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alfonso Jimenez