Class: AWS::EC2::RouteTable
- Inherits:
-
Resource
- Object
- Core::Resource
- Resource
- AWS::EC2::RouteTable
- Includes:
- TaggedItem
- Defined in:
- lib/aws/ec2/route_table/route.rb,
lib/aws/ec2/route_table.rb,
lib/aws/ec2/route_table/association.rb
Overview
Represents a single route in a RouteTable.
# enumerating routes within a route table
ec2 = AWS::EC2.new
route_table = ec2.route_tables.first
route_table.routes.each do |route|
# ...
end
Defined Under Namespace
Classes: Association, Route
Instance Attribute Summary collapse
- #route_table_id ⇒ String (also: #id) readonly
Instance Method Summary collapse
-
#associations ⇒ Array<RouteTable::Association>
Returns an array of Association objects (association to subnets).
-
#create_route(destination_cidr_block, options = {}) ⇒ nil
Creates a new route in this route route.
-
#delete ⇒ nil
Deletes this route table.
- #delete_route(destination_cidr_block) ⇒ nil
-
#initialize(route_table_id, options = {}) ⇒ RouteTable
constructor
A new instance of RouteTable.
-
#main? ⇒ Boolean
Returns true if this is the main (default) route table.
-
#replace_route(destination_cidr_block, options = {}) ⇒ nil
Replaces an existing route within a route table in a VPC.
-
#routes ⇒ Array<Route>
Returns an array of routes (Route objects) belonging to this route table.
-
#subnets ⇒ Array<Subnet>
Returns an array of subnets (Subnet) that currently associated to this route table.
-
#vpc ⇒ VPC
Returns the VPC this route table belongs to.
Methods included from TaggedItem
Constructor Details
#initialize(route_table_id, options = {}) ⇒ RouteTable
Returns a new instance of RouteTable.
24 25 26 27 |
# File 'lib/aws/ec2/route_table.rb', line 24 def initialize route_table_id, = {} @route_table_id = route_table_id super end |
Instance Attribute Details
#route_table_id ⇒ String (readonly) Also known as: id
30 31 32 |
# File 'lib/aws/ec2/route_table.rb', line 30 def route_table_id @route_table_id end |
Instance Method Details
#associations ⇒ Array<RouteTable::Association>
Returns an array of Association objects (association to subnets).
108 109 110 111 112 113 114 |
# File 'lib/aws/ec2/route_table.rb', line 108 def associations association_set.collect do |details| Association.new(self, details[:route_table_association_id], details[:subnet_id]) end end |
#create_route(destination_cidr_block, options = {}) ⇒ nil
Creates a new route in this route route. The route must be attached to a gateway, instance or network interface.
146 147 148 149 |
# File 'lib/aws/ec2/route_table.rb', line 146 def create_route destination_cidr_block, = {} client.create_route((destination_cidr_block, )) nil end |
#delete ⇒ nil
Deletes this route table. The route table must not be associated with a subnet. You can’t delete the main route table.
171 172 173 174 |
# File 'lib/aws/ec2/route_table.rb', line 171 def delete client.delete_route_table(:route_table_id => route_table_id) nil end |
#delete_route(destination_cidr_block) ⇒ nil
163 164 165 166 |
# File 'lib/aws/ec2/route_table.rb', line 163 def delete_route destination_cidr_block client.delete_route((destination_cidr_block)) nil end |
#main? ⇒ Boolean
Returns true if this is the main (default) route table.
54 55 56 57 |
# File 'lib/aws/ec2/route_table.rb', line 54 def main? @main = !!associations.find{|a| a.main? } if @main.nil? @main end |
#replace_route(destination_cidr_block, options = {}) ⇒ nil
Replaces an existing route within a route table in a VPC.
155 156 157 158 |
# File 'lib/aws/ec2/route_table.rb', line 155 def replace_route destination_cidr_block, = {} client.replace_route((destination_cidr_block, )) nil end |
#routes ⇒ Array<Route>
Returns an array of routes (Route objects) belonging to this route table.
118 119 120 121 122 |
# File 'lib/aws/ec2/route_table.rb', line 118 def routes route_set.map do |route_details| Route.new(self, route_details) end end |
#subnets ⇒ Array<Subnet>
Returns an array of subnets (Subnet) that currently associated to this route table.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/aws/ec2/route_table.rb', line 66 def subnets subnets = associations.map(&:subnet) # The default route table has a single association where #subnet # returns nil (the main association). If this is not the main # route table we can safely return the subnets. return subnets unless subnets.include?(nil) subnets.compact! # This is the default route table and to get the complete list of # subnets we have to find all subnets without an association AWS.memoize do # every subnet all_subnets = vpc.subnets.to_a # subnets assigned directly to a route table associated_subnets = vpc.route_tables. map(&:associations).flatten. map(&:subnet).flatten. compact # subnets NOT assigned to a route table, these default as # belonging to the default route table through the "main" # association unassociated_subnets = all_subnets.inject([]) do |list,subnet| unless associated_subnets.include?(subnet) list << subnet end list end subnets + unassociated_subnets end end |