Make sure every NetworkInterface has a private IP

AWS always assigns a primary IP address to Network Interfaces.
Using a test account (modified the IP):

    >>> import boto
    >>> vpc = boto.connect_vpc()
    >>> eni = vpc.create_network_interface(subnet_id)
    >>> eni.private_ip_addresses
    [PrivateIPAddress(10.1.2.3, primary=True)]
This commit is contained in:
Hugo Lopes Tavares 2019-03-27 16:23:49 -04:00
parent 64152f4cda
commit d4e39146b7
2 changed files with 3 additions and 2 deletions

View File

@ -189,7 +189,7 @@ class NetworkInterface(TaggedEC2Resource):
self.ec2_backend = ec2_backend
self.id = random_eni_id()
self.device_index = device_index
self.private_ip_address = private_ip_address
self.private_ip_address = private_ip_address or random_private_ip()
self.subnet = subnet
self.instance = None
self.attachment_id = None

View File

@ -36,7 +36,8 @@ def test_elastic_network_interfaces():
all_enis.should.have.length_of(1)
eni = all_enis[0]
eni.groups.should.have.length_of(0)
eni.private_ip_addresses.should.have.length_of(0)
eni.private_ip_addresses.should.have.length_of(1)
eni.private_ip_addresses[0].private_ip_address.startswith('10.').should.be.true
with assert_raises(EC2ResponseError) as ex:
conn.delete_network_interface(eni.id, dry_run=True)