Added the ability to associate route tables.

This commit is contained in:
Omer Katz 2014-09-29 19:48:29 +03:00
parent 40230406fb
commit 4110fb06eb
2 changed files with 48 additions and 2 deletions

View File

@ -739,6 +739,21 @@ def route_table_exists(route_table_id, region=None, key=None, keyid=None, profil
return False
def associate_route_table(route_table_id, subnet_id, region=None, key=None, keyid=None, profile=None):
conn = _get_conn(region, key, keyid, profile)
if not conn:
return False
try:
association_id = conn.associate_route_table(route_table_id, subnet_id)
log.info('Route table {0} was associated with subnet {1}'.format(route_table_id, subnet_id))
return association_id
except boto.exception.BotoServerError as e:
log.error(e)
return False
def disassociate_route_table(association_id, region=None, key=None, keyid=None, profile=None):
conn = _get_conn(region, key, keyid, profile)
if not conn:

View File

@ -779,7 +779,38 @@ class BotoVpcRouteTablesTestCase(BotoVpcTestCaseBase):
@mock_ec2
@expectedNotImplementedFailure
def test_when_disassociating_route_table_succeeds_the_disassociate_route_table_method_should_return_true(self):
def test_when_associating_a_route_table_succeeds_the_associate_route_table_method_should_return_the_association_id(self):
vpc = self._create_vpc()
subnet = self._create_subnet(vpc.id)
route_table = self._create_route_table(vpc.id)
assocation_id = boto_vpc.associate_route_table(route_table.id, subnet.id)
self.assertTrue(assocation_id)
@mock_ec2
@expectedNotImplementedFailure
def test_when_associating_a_route_table_with_a_non_existent_route_table_the_associate_route_table_method_should_return_false(self):
vpc = self._create_vpc()
subnet = self._create_subnet(vpc.id)
assocation_id = boto_vpc.associate_route_table('fake', subnet.id)
self.assertFalse(assocation_id)
@mock_ec2
@expectedNotImplementedFailure
def test_when_associating_a_route_table_with_a_non_existent_route_table_the_associate_route_table_method_should_return_false(self):
vpc = self._create_vpc()
route_table = self._create_route_table(vpc.id)
assocation_id = boto_vpc.associate_route_table(route_table.id, 'fake')
self.assertFalse(assocation_id)
@mock_ec2
@expectedNotImplementedFailure
def test_when_disassociating_a_route_table_succeeds_the_disassociate_route_table_method_should_return_true(self):
vpc = self._create_vpc()
subnet = self._create_subnet(vpc.id)
route_table = self._create_route_table(vpc.id)