Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add elastic IP support

- if micro bosh uses an elastic IP and the deployed instance uses
  one too, it connects using the elastic IP

Change-Id: Ie42ec1312bf23516a7d68c0c9e53309e8a78e494
  • Loading branch information...
commit aa57942fcdcd7382bc6c952176846d3bc5efefb4 1 parent 4421b08
@pmenglund pmenglund authored
View
21 aws_registry/lib/aws_registry/instance_manager.rb
@@ -31,7 +31,7 @@ def update_settings(instance_id, settings)
# check will be performed to see if it instance id
# actually has this IP address according to EC2.
def read_settings(instance_id, remote_ip = nil)
- check_instance_ip(remote_ip, instance_id) if remote_ip
+ check_instance_ips(remote_ip, instance_id) if remote_ip
get_instance(instance_id).settings
end
@@ -42,12 +42,13 @@ def delete_settings(instance_id)
private
- def check_instance_ip(ip, instance_id)
+ def check_instance_ips(ip, instance_id)
return if ip == "127.0.0.1"
- actual_ip = instance_private_ip(instance_id)
- unless ip == actual_ip
+ actual_ips = instance_ips(instance_id)
+ unless actual_ips.include?(ip)
raise InstanceError, "Instance IP mismatch, expected IP is " \
- "`%s', actual IP is `%s'" % [ ip, actual_ip ]
+ "`%s', actual IP(s): `%s'" %
+ [ ip, actual_ips.join(", ") ]
end
end
@@ -61,8 +62,14 @@ def get_instance(instance_id)
instance
end
- def instance_private_ip(instance_id)
- @ec2.instances[instance_id].private_ip_address
+ # Get the list of IPs belonging to this instance
+ def instance_ips(instance_id)
+ instance = @ec2.instances[instance_id]
+ ips = [instance.private_ip_address, instance.public_ip_address]
+ if instance.has_elastic_ip?
+ ips << instance.elastic_ip.public_ip
+ end
+ ips
rescue AWS::Errors::Base => e
raise Bosh::AwsRegistry::AwsError, "AWS error: #{e}"
end
View
28 aws_registry/spec/unit/instance_manager_spec.rb
@@ -17,30 +17,44 @@ def create_instance(params)
Bosh::AwsRegistry::Models::AwsInstance.create(params)
end
- def actual_ip_is(ip)
+ def actual_ip_is(public_ip, private_ip, eip=nil)
instances = mock("instances")
instance = mock("instance")
+ if eip
+ elastic_ip = mock("elastic_ip", :public_ip => eip)
+ instance.should_receive(:has_elastic_ip?).and_return(true)
+ instance.should_receive(:elastic_ip).and_return(elastic_ip)
+ else
+ instance.should_receive(:has_elastic_ip?).and_return(false)
+ end
@ec2.should_receive(:instances).and_return(instances)
instances.should_receive(:[]).with("foo").and_return(instance)
- instance.should_receive(:private_ip_address).and_return(ip)
+ instance.should_receive(:private_ip_address).and_return(public_ip)
+ instance.should_receive(:public_ip_address).and_return(private_ip)
end
describe "reading settings" do
it "returns settings after verifying IP address" do
create_instance(:instance_id => "foo", :settings => "bar")
- actual_ip_is("10.0.0.1")
+ actual_ip_is("10.0.0.1", "10.0.1.1")
manager.read_settings("foo", "10.0.0.1").should == "bar"
end
+ it "returns settings after verifying elastic IP address" do
+ create_instance(:instance_id => "foo", :settings => "bar")
+ actual_ip_is("10.0.0.1", "10.0.1.1", "10.0.3.1")
+ manager.read_settings("foo", "10.0.3.1").should == "bar"
+ end
+
it "raises an error if IP cannot be verified" do
create_instance(:instance_id => "foo", :settings => "bar")
- actual_ip_is("10.0.0.2")
+ actual_ip_is("10.0.0.1", "10.0.1.1")
expect {
- manager.read_settings("foo", "10.0.0.1")
+ manager.read_settings("foo", "10.0.3.1")
}.to raise_error(Bosh::AwsRegistry::InstanceError,
- "Instance IP mismatch, expected IP is `10.0.0.1', " \
- "actual IP is `10.0.0.2'")
+ "Instance IP mismatch, expected IP is `10.0.3.1', " \
+ "actual IP(s): `10.0.0.1, 10.0.1.1'")
end
it "doesn't check remote IP if it's not provided" do
Please sign in to comment.
Something went wrong with that request. Please try again.