Add private-dns-name filter and fix regional DNS (#1076)

* add private-dns-name to filter_dict_attribute_mapping

* add region_name attribute to Instance and InstanceResponse

* set dns name based on region

* test private-dns-name and network-interface.private-dns-name filters. checking both regional dns formats

* update test_ec2_classic_has_public_ip_address to use correct dns values
This commit is contained in:
Daniel Lutsch 2017-08-23 01:39:50 -07:00 committed by Jack Danger
commit 945b984538
4 changed files with 45 additions and 8 deletions

View file

@ -409,6 +409,33 @@ def test_get_instances_filtering_by_image_id():
'Values': [image_id]}])['Reservations']
reservations[0]['Instances'].should.have.length_of(1)
@mock_ec2
def test_get_instances_filtering_by_private_dns():
image_id = 'ami-1234abcd'
client = boto3.client('ec2', region_name='us-east-1')
conn = boto3.resource('ec2', 'us-east-1')
conn.create_instances(ImageId=image_id,
MinCount=1,
MaxCount=1,
PrivateIpAddress='10.0.0.1')
reservations = client.describe_instances(Filters=[
{'Name': 'private-dns-name', 'Values': ['ip-10-0-0-1.ec2.internal']}
])['Reservations']
reservations[0]['Instances'].should.have.length_of(1)
@mock_ec2
def test_get_instances_filtering_by_ni_private_dns():
image_id = 'ami-1234abcd'
client = boto3.client('ec2', region_name='us-west-2')
conn = boto3.resource('ec2', 'us-west-2')
conn.create_instances(ImageId=image_id,
MinCount=1,
MaxCount=1,
PrivateIpAddress='10.0.0.1')
reservations = client.describe_instances(Filters=[
{'Name': 'network-interface.private-dns-name', 'Values': ['ip-10-0-0-1.us-west-2.compute.internal']}
])['Reservations']
reservations[0]['Instances'].should.have.length_of(1)
@mock_ec2_deprecated
def test_get_instances_filtering_by_tag():
@ -943,11 +970,9 @@ def test_ec2_classic_has_public_ip_address():
reservation = conn.run_instances('ami-1234abcd', key_name="keypair_name")
instance = reservation.instances[0]
instance.ip_address.should_not.equal(None)
instance.public_dns_name.should.contain(instance.ip_address)
instance.public_dns_name.should.contain(instance.ip_address.replace('.', '-'))
instance.private_ip_address.should_not.equal(None)
instance.private_dns_name.should.contain(instance.private_ip_address)
instance.private_dns_name.should.contain(instance.private_ip_address.replace('.', '-'))
@mock_ec2_deprecated
def test_run_instance_with_keypair():