Route Tables: Added support for associate/disassociate subnets. (fixed idempotency)
This commit is contained in:
parent
50d74b4811
commit
89fd71eb16
2 changed files with 24 additions and 0 deletions
|
|
@ -1647,6 +1647,14 @@ class RouteTableBackend(object):
|
|||
return True
|
||||
|
||||
def associate_route_table(self, route_table_id, subnet_id):
|
||||
# Idempotent if association already exists.
|
||||
route_tables_by_subnet = ec2_backend.get_all_route_tables(filters={'association.subnet-id':[subnet_id]})
|
||||
if route_tables_by_subnet:
|
||||
for association_id,check_subnet_id in route_tables_by_subnet[0].associations.items():
|
||||
if subnet_id == check_subnet_id:
|
||||
return association_id
|
||||
|
||||
# Association does not yet exist, so create it.
|
||||
route_table = self.get_route_table(route_table_id)
|
||||
subnet = self.get_subnet(subnet_id) # Validate subnet exists
|
||||
association_id = random_subnet_association_id()
|
||||
|
|
@ -1660,9 +1668,17 @@ class RouteTableBackend(object):
|
|||
raise InvalidAssociationIdError(association_id)
|
||||
|
||||
def replace_route_table_association(self, association_id, route_table_id):
|
||||
# Idempotent if association already exists.
|
||||
new_route_table = ec2_backend.get_route_table(route_table_id)
|
||||
if association_id in new_route_table.associations:
|
||||
return association_id
|
||||
|
||||
# Find route table which currently has the association, error if none.
|
||||
route_tables_by_association_id = ec2_backend.get_all_route_tables(filters={'association.route-table-association-id':[association_id]})
|
||||
if not route_tables_by_association_id:
|
||||
raise InvalidAssociationIdError(association_id)
|
||||
|
||||
# Remove existing association, create new one.
|
||||
previous_route_table = route_tables_by_association_id[0]
|
||||
subnet_id = previous_route_table.associations.pop(association_id,None)
|
||||
return self.associate_route_table(route_table_id, subnet_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue