This commit is contained in:
Bert Blommers 2020-04-29 16:29:25 +01:00
commit 2d0087d500
4 changed files with 60 additions and 58 deletions

View file

@ -2881,24 +2881,25 @@ class VPCBackend(object):
vpc = self.get_vpc(vpc_id)
return vpc.associate_vpc_cidr_block(cidr_block, amazon_provided_ipv6_cidr_block)
def create_vpc_endpoint(self,
vpc_id,
service_name,
type=None,
policy_document=False,
route_table_ids=None,
subnet_ids=[],
network_interface_ids=[],
dns_entries=None,
client_token=None,
security_group=None,
tag_specifications=None,
private_dns_enabled=None
):
def create_vpc_endpoint(
self,
vpc_id,
service_name,
type=None,
policy_document=False,
route_table_ids=None,
subnet_ids=[],
network_interface_ids=[],
dns_entries=None,
client_token=None,
security_group=None,
tag_specifications=None,
private_dns_enabled=None,
):
vpc_endpoint_id = generate_vpc_end_point_id(vpc_id)
#validates if vpc is present or not.
# validates if vpc is present or not.
self.get_vpc(vpc_id)
if type and type.lower() == "interface":
@ -2911,15 +2912,12 @@ class VPCBackend(object):
dns_entries = create_dns_entries(service_name, vpc_endpoint_id)
else :
else:
# considering gateway if type is not mentioned.
service_destination_cidr = randor_ipv4_cidr()
for route_table_id in route_table_ids:
self.create_route(
route_table_id,
service_destination_cidr
)
self.create_route(route_table_id, service_destination_cidr)
if dns_entries:
dns_entries = [dns_entries]
@ -2936,7 +2934,7 @@ class VPCBackend(object):
client_token,
security_group,
tag_specifications,
private_dns_enabled
private_dns_enabled,
)
self.vpc_end_points[vpc_endpoint_id] = vpc_end_point
@ -3560,7 +3558,7 @@ class VPCEndPoint(TaggedEC2Resource):
type=None,
policy_document=False,
route_table_ids=None,
subnet_ids =None,
subnet_ids=None,
network_interface_ids=None,
dns_entries=None,
client_token=None,

View file

@ -176,22 +176,20 @@ class VPCs(BaseResponse):
security_group = self._get_param("SecurityGroup")
vpc_end_point = self.ec2_backend.create_vpc_endpoint(
vpc_id=vpc_id,
service_name=service_name,
type=type,
policy_document=policy_document,
route_table_ids=route_table_ids,
subnet_ids=subnet_ids,
client_token=client_token,
security_group=security_group,
tag_specifications=tag_specifications,
private_dns_enabled=private_dns_enabled
vpc_id=vpc_id,
service_name=service_name,
type=type,
policy_document=policy_document,
route_table_ids=route_table_ids,
subnet_ids=subnet_ids,
client_token=client_token,
security_group=security_group,
tag_specifications=tag_specifications,
private_dns_enabled=private_dns_enabled,
)
template = self.response_template(CREATE_VPC_END_POINT)
return template.render(
vpc_end_point=vpc_end_point
)
return template.render(vpc_end_point=vpc_end_point)
CREATE_VPC_RESPONSE = """
@ -450,4 +448,4 @@ CREATE_VPC_END_POINT = """ <CreateVpcEndpointResponse xmlns="http://monitoring.a
</dnsEntrySet>
<creationTimestamp>{{ vpc_end_point.created_at }}</creationTimestamp>
</vpcEndpoint>
</CreateVpcEndpointResponse>"""
</CreateVpcEndpointResponse>"""

View file

@ -194,13 +194,14 @@ def generate_route_id(route_table_id, cidr_block):
def generate_vpc_end_point_id(vpc_id):
return "%s-%s" % ('vpce', vpc_id[4:])
return "%s-%s" % ("vpce", vpc_id[4:])
def create_dns_entries(service_name, vpc_endpoint_id):
dns_entries = {}
dns_entries["dns_name"] = "{}-{}.{}".format(vpc_endpoint_id,
random_resource_id(8), service_name)
dns_entries["dns_name"] = "{}-{}.{}".format(
vpc_endpoint_id, random_resource_id(8), service_name
)
dns_entries["hosted_zone_id"] = random_resource_id(13).upper()
return dns_entries