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

@ -366,6 +366,7 @@ class Instance(TaggedEC2Resource, BotoInstance):
self.user_data = user_data
self.security_groups = security_groups
self.instance_type = kwargs.get("instance_type", "m1.small")
self.region_name = kwargs.get("region_name", "us-east-1")
placement = kwargs.get("placement", None)
self.vpc_id = None
self.subnet_id = kwargs.get("subnet_id")
@ -433,7 +434,11 @@ class Instance(TaggedEC2Resource, BotoInstance):
@property
def private_dns(self):
return "ip-{0}.ec2.internal".format(self.private_ip)
formatted_ip = self.private_ip.replace('.', '-')
if self.region_name == "us-east-1":
return "ip-{0}.ec2.internal".format(formatted_ip)
else:
return "ip-{0}.{1}.compute.internal".format(formatted_ip, self.region_name)
@property
def public_ip(self):
@ -442,7 +447,11 @@ class Instance(TaggedEC2Resource, BotoInstance):
@property
def public_dns(self):
if self.public_ip:
return "ec2-{0}.compute-1.amazonaws.com".format(self.public_ip)
formatted_ip = self.public_ip.replace('.', '-')
if self.region_name == "us-east-1":
return "ec2-{0}.compute-1.amazonaws.com".format(formatted_ip)
else:
return "ec2-{0}.{1}.compute.amazonaws.com".format(formatted_ip, self.region_name)
@classmethod
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):

View file

@ -48,11 +48,12 @@ class InstanceResponse(BaseResponse):
"AssociatePublicIpAddress", [None])[0]
key_name = self.querystring.get("KeyName", [None])[0]
tags = self._parse_tag_specification("TagSpecification")
region_name = self.region
if self.is_not_dryrun('RunInstance'):
new_reservation = self.ec2_backend.add_instances(
image_id, min_count, user_data, security_group_names,
instance_type=instance_type, placement=placement, subnet_id=subnet_id,
instance_type=instance_type, placement=placement, region_name=region_name, subnet_id=subnet_id,
key_name=key_name, security_group_ids=security_group_ids,
nics=nics, private_ip=private_ip, associate_public_ip=associate_public_ip,
tags=tags)

View file

@ -392,7 +392,9 @@ filter_dict_attribute_mapping = {
'ip-address': 'public_ip',
'availability-zone': 'placement',
'architecture': 'architecture',
'image-id': 'image_id'
'image-id': 'image_id',
'network-interface.private-dns-name': 'private_dns',
'private-dns-name': 'private_dns'
}