Created
February 21, 2013 00:07
-
-
Save pmenglund/5000861 to your computer and use it in GitHub Desktop.
elb stuff in aws cpi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bosh_aws_cpi/lib/cloud/aws/cloud.rb b/bosh_aws_cpi/lib/cloud/aws/cloud.rb | |
index 6e2bfab..6a66b0a 100644 | |
--- a/bosh_aws_cpi/lib/cloud/aws/cloud.rb | |
+++ b/bosh_aws_cpi/lib/cloud/aws/cloud.rb | |
@@ -56,7 +56,9 @@ module Bosh::AwsCloud | |
# AWS Ruby SDK is threadsafe but Ruby autoload isn't, | |
# so we need to trigger eager autoload while constructing CPI | |
AWS.eager_autoload! | |
- @ec2 = AWS::EC2.new(aws_params) | |
+ | |
+ AWS.params(aws_params) | |
+ @ec2 = AWS::EC2.new | |
# Registry updates are not really atomic in relation to | |
# EC2 API calls, so they might get out of sync. Cloudcheck | |
diff --git a/bosh_aws_cpi/lib/cloud/aws/instance_manager.rb b/bosh_aws_cpi/lib/cloud/aws/instance_manager.rb | |
index badbaf1..fbc83bb 100644 | |
--- a/bosh_aws_cpi/lib/cloud/aws/instance_manager.rb | |
+++ b/bosh_aws_cpi/lib/cloud/aws/instance_manager.rb | |
@@ -2,6 +2,7 @@ module Bosh::AwsCloud | |
class InstanceManager | |
include Helpers | |
+ attr_reader :instance | |
attr_reader :instance_params | |
def initialize(region, registry, az_selector=nil) | |
@@ -26,11 +27,18 @@ module Bosh::AwsCloud | |
) | |
@logger.info("Creating new instance with: #{instance_params.inspect}") | |
- @region.instances.create instance_params | |
+ @instance = @region.instances.create(instance_params) | |
+ | |
+ elbs = resource_pool['elbs'] | |
+ attach_to_load_balancers(elbs) if elbs | |
+ | |
+ instance | |
end | |
def terminate(instance_id, fast=false) | |
- instance = @region.instances[instance_id] | |
+ @instance = @region.instances[instance_id] | |
+ | |
+ remove_from_load_balancers | |
instance.terminate | |
@@ -52,6 +60,25 @@ module Bosh::AwsCloud | |
end | |
end | |
+ def attach_to_load_balancers(elbs) | |
+ elb = AWS::ELB.new | |
+ | |
+ elbs.each do |load_balancer| | |
+ elb.register_instances_with_load_balancer(:load_balancer_name => load_balancer, | |
+ :instances => [instance.id]) | |
+ end | |
+ end | |
+ | |
+ def remove_from_load_balancers | |
+ elb = AWS::ELB.new | |
+ | |
+ # should we only do this for the elbs explicitly listed in the resource_pool? | |
+ elb.load_balancers.each do |load_balancer| | |
+ i = load_balancer.instances[instance.id] | |
+ i.remove_from_load_balancer if i.exist? | |
+ end | |
+ end | |
+ | |
# Soft reboots EC2 instance | |
# @param [AWS::EC2::Instance] instance EC2 instance | |
def reboot(instance_id) | |
diff --git a/bosh_aws_cpi/lib/cloud/aws/manual_network.rb b/bosh_aws_cpi/lib/cloud/aws/manual_network.rb | |
index 166c880..3cb070e 100644 | |
--- a/bosh_aws_cpi/lib/cloud/aws/manual_network.rb | |
+++ b/bosh_aws_cpi/lib/cloud/aws/manual_network.rb | |
@@ -14,6 +14,7 @@ module Bosh::AwsCloud | |
raise Bosh::Clouds::CloudError, "subnet required for manual network" | |
end | |
@subnet = @cloud_properties["subnet"] | |
+ @elb = @cloud_properties["elb"] | |
end | |
def private_ip | |
diff --git a/bosh_aws_cpi/lib/cloud/aws/network_configurator.rb b/bosh_aws_cpi/lib/cloud/aws/network_configurator.rb | |
index 730c92c..0663c75 100644 | |
--- a/bosh_aws_cpi/lib/cloud/aws/network_configurator.rb | |
+++ b/bosh_aws_cpi/lib/cloud/aws/network_configurator.rb | |
@@ -1,4 +1,4 @@ | |
-76# Copyright (c) 2009-2012 VMware, Inc. | |
+# Copyright (c) 2009-2012 VMware, Inc. | |
module Bosh::AwsCloud | |
## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment