|
|
@@ -1026,6 +1026,8 @@ class AWSRouter(BaseRouter):
|
|
|
def __init__(self, provider, router):
|
|
|
super(AWSRouter, self).__init__(provider)
|
|
|
self._router = router
|
|
|
+ self._route_table = None
|
|
|
+ self._ROUTE_CIDR = '0.0.0.0/0'
|
|
|
|
|
|
@property
|
|
|
def id(self):
|
|
|
@@ -1078,12 +1080,35 @@ class AWSRouter(BaseRouter):
|
|
|
self.id, self.network_id)
|
|
|
|
|
|
def add_route(self, subnet_id):
|
|
|
- # For AWS, routes are added to a route table. A route table is assoc.
|
|
|
- # with a network vs. a subnet so we don't use the supplied subnet.
|
|
|
- rt = self._provider.vpc_conn.get_all_route_tables(
|
|
|
- filters={'vpc-id': self.network_id})[0]
|
|
|
+ """
|
|
|
+ Add a default route to this router.
|
|
|
+
|
|
|
+ For AWS, routes are added to a route table. A route table is assoc.
|
|
|
+ with a network vs. a subnet so we retrieve the network via the subnet.
|
|
|
+ Note that the subnet must belong to the same network as the router
|
|
|
+ is attached to.
|
|
|
+
|
|
|
+ Further, only a single route can be added, targeting the Internet
|
|
|
+ (i.e., destination CIDR block ``0.0.0.0/0``).
|
|
|
+ """
|
|
|
+ sn = self._provider.vpc_conn.get_all_subnets([subnet_id])[0]
|
|
|
+ self._route_table = self._provider.vpc_conn.get_all_route_tables(
|
|
|
+ filters={'vpc-id': sn.vpc_id})[0]
|
|
|
return self._provider.vpc_conn.create_route(
|
|
|
- rt.id, '0.0.0.0/0', self.id)
|
|
|
+ self._route_table.id, self._ROUTE_CIDR, self.id)
|
|
|
+
|
|
|
+ def remove_route(self, subnet_id):
|
|
|
+ """
|
|
|
+ Remove the default Internet route from this router.
|
|
|
+
|
|
|
+ .. seealso:: ``add_route`` method
|
|
|
+ """
|
|
|
+ if not self._route_table:
|
|
|
+ sn = self._provider.vpc_conn.get_all_subnets([subnet_id])[0]
|
|
|
+ self._route_table = self._provider.vpc_conn.get_all_route_tables(
|
|
|
+ filters={'vpc-id': sn.vpc_id})[0]
|
|
|
+ return self._provider.vpc_conn.remove_route(
|
|
|
+ self._route_table.id, self._ROUTE_CIDR)
|
|
|
|
|
|
|
|
|
class AWSLaunchConfig(BaseLaunchConfig):
|