Added the ability to create routes.

This commit is contained in:
Omer Katz 2014-09-29 20:11:08 +03:00
parent 4110fb06eb
commit ff48e4aebf
2 changed files with 38 additions and 3 deletions

View File

@ -773,6 +773,25 @@ def disassociate_route_table(association_id, region=None, key=None, keyid=None,
return False
def create_route(route_table_id, destination_cidr_block, gateway_id=None, instance_id=None, interface_id=None,
region=None, key=None, keyid=None, profile=None):
conn = _get_conn(region, key, keyid, profile)
if not conn:
return False
try:
if conn.create_route(route_table_id, destination_cidr_block, gateway_id=gateway_id, instance_id=instance_id,
interface_id=interface_id):
log.info('Route with cider block {0} on route table {1} was created'.format(route_table_id, destination_cidr_block))
return True
else:
log.warning('Route with cider block {0} on route table {1} was not created'.format(route_table_id, destination_cidr_block))
except boto.exception.BotoServerError as e:
log.error(e)
return False
def _get_conn(region, key, keyid, profile):
'''
Get a boto connection to vpc.

View File

@ -784,7 +784,7 @@ class BotoVpcRouteTablesTestCase(BotoVpcTestCaseBase):
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)
assocation_id = boto_vpc.associate_route_table(route_table.id, subnet.id, **conn_parameters)
self.assertTrue(assocation_id)
@ -794,7 +794,7 @@ class BotoVpcRouteTablesTestCase(BotoVpcTestCaseBase):
vpc = self._create_vpc()
subnet = self._create_subnet(vpc.id)
assocation_id = boto_vpc.associate_route_table('fake', subnet.id)
assocation_id = boto_vpc.associate_route_table('fake', subnet.id, **conn_parameters)
self.assertFalse(assocation_id)
@ -804,7 +804,7 @@ class BotoVpcRouteTablesTestCase(BotoVpcTestCaseBase):
vpc = self._create_vpc()
route_table = self._create_route_table(vpc.id)
assocation_id = boto_vpc.associate_route_table(route_table.id, 'fake')
assocation_id = boto_vpc.associate_route_table(route_table.id, 'fake', **conn_parameters)
self.assertFalse(assocation_id)
@ -821,6 +821,22 @@ class BotoVpcRouteTablesTestCase(BotoVpcTestCaseBase):
self.assertTrue(dhcp_disassociate_result)
@mock_ec2
@expectedNotImplementedFailure
def test_when_creating_a_route_succeeds_the_create_route_method_should_return_true(self):
vpc = self._create_vpc()
route_table = self._create_route_table(vpc.id)
route_creation_result = boto_vpc.create_route(route_table.id, cidr_block, **conn_parameters)
self.assertTrue(route_creation_result)
@mock_ec2
@expectedNotImplementedFailure
def test_when_creating_a_route_with_a_non_existent_route_table_the_create_route_method_should_return_false(self):
route_creation_result = boto_vpc.create_route('fake', cidr_block, **conn_parameters)
self.assertFalse(route_creation_result)
if __name__ == '__main__':
from integration import run_tests