From 27f1bece9b2aab2ad7e0d2bf705101b28c48eab6 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Wed, 12 Oct 2016 22:02:06 -0400 Subject: [PATCH] Fix assigning public ip to instances. Closes #729. --- moto/ec2/models.py | 5 ++++ moto/ec2/responses/instances.py | 2 ++ tests/test_ec2/test_elastic_ip_addresses.py | 27 +++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index e3342c8c..418cac3f 100755 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -549,6 +549,10 @@ class Instance(BotoInstance, TaggedEC2Resource): self.attach_eni(use_nic, device_index) + def set_ip(self, ip_address): + # Should we be creating a new ENI? + self.nics[0].public_ip = ip_address + def attach_eni(self, eni, device_index): device_index = int(device_index) self.nics[device_index] = eni @@ -2663,6 +2667,7 @@ class ElasticAddressBackend(object): eip.eni.public_ip = eip.public_ip if eip.domain == "vpc": eip.association_id = random_eip_association_id() + instance.set_ip(eip.public_ip) return eip diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 9670d64f..2fed6011 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -207,6 +207,7 @@ EC2_RUN_INSTANCES = """