1# Copyright (c) 2009-2010 Mitch Garnaat http://garnaat.org/ 2# 3# Permission is hereby granted, free of charge, to any person obtaining a 4# copy of this software and associated documentation files (the 5# "Software"), to deal in the Software without restriction, including 6# without limitation the rights to use, copy, modify, merge, publish, dis- 7# tribute, sublicense, and/or sell copies of the Software, and to permit 8# persons to whom the Software is furnished to do so, subject to the fol- 9# lowing conditions: 10# 11# The above copyright notice and this permission notice shall be included 12# in all copies or substantial portions of the Software. 13# 14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 16# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 17# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20# IN THE SOFTWARE. 21 22""" 23Represents a Route Table 24""" 25 26from boto.ec2.ec2object import TaggedEC2Object 27from boto.resultset import ResultSet 28 29class RouteTable(TaggedEC2Object): 30 31 def __init__(self, connection=None): 32 super(RouteTable, self).__init__(connection) 33 self.id = None 34 self.vpc_id = None 35 self.routes = [] 36 self.associations = [] 37 38 def __repr__(self): 39 return 'RouteTable:%s' % self.id 40 41 def startElement(self, name, attrs, connection): 42 result = super(RouteTable, self).startElement(name, attrs, connection) 43 44 if result is not None: 45 # Parent found an interested element, just return it 46 return result 47 48 if name == 'routeSet': 49 self.routes = ResultSet([('item', Route)]) 50 return self.routes 51 elif name == 'associationSet': 52 self.associations = ResultSet([('item', RouteAssociation)]) 53 return self.associations 54 else: 55 return None 56 57 def endElement(self, name, value, connection): 58 if name == 'routeTableId': 59 self.id = value 60 elif name == 'vpcId': 61 self.vpc_id = value 62 else: 63 setattr(self, name, value) 64 65class Route(object): 66 def __init__(self, connection=None): 67 self.destination_cidr_block = None 68 self.gateway_id = None 69 self.instance_id = None 70 self.interface_id = None 71 self.vpc_peering_connection_id = None 72 self.state = None 73 74 def __repr__(self): 75 return 'Route:%s' % self.destination_cidr_block 76 77 def startElement(self, name, attrs, connection): 78 return None 79 80 def endElement(self, name, value, connection): 81 if name == 'destinationCidrBlock': 82 self.destination_cidr_block = value 83 elif name == 'gatewayId': 84 self.gateway_id = value 85 elif name == 'instanceId': 86 self.instance_id = value 87 elif name == 'networkInterfaceId': 88 self.interface_id = value 89 elif name == 'vpcPeeringConnectionId': 90 self.vpc_peering_connection_id = value 91 elif name == 'state': 92 self.state = value 93 94class RouteAssociation(object): 95 def __init__(self, connection=None): 96 self.id = None 97 self.route_table_id = None 98 self.subnet_id = None 99 self.main = False 100 101 def __repr__(self): 102 return 'RouteAssociation:%s' % self.id 103 104 def startElement(self, name, attrs, connection): 105 return None 106 107 def endElement(self, name, value, connection): 108 if name == 'routeTableAssociationId': 109 self.id = value 110 elif name == 'routeTableId': 111 self.route_table_id = value 112 elif name == 'subnetId': 113 self.subnet_id = value 114 elif name == 'main': 115 self.main = value == 'true' 116