class AWS::EC2::RouteTable
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
Attributes
@return [String]
@return [String]
Public Class Methods
AWS::Core::Resource::new
# File lib/aws/ec2/route_table.rb, line 24 def initialize route_table_id, options = {} @route_table_id = route_table_id super end
Public Instance Methods
@return [Array<RouteTable::Association>] Returns an array of
{RouteTable::Association} objects (association to subnets).
# 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
Creates a new route in this route route. The route must be attached to a gateway, instance or network interface.
@param [String] destination_cidr_block The CIDR address block
used for the destination match. For example: 0.0.0.0/0. Routing decisions are based on the most specific match.
@param [Hash] options
@option options [InternetGateway,String] :internet_gateway
An {InternetGateway} object or an internet gateway id string to attach the route to.
@option options [Instance,String] :instance An {Instance} object
or instance id string to attach the route to.
@option options [NetworkInterface,String] :network_interface
A {NetworkInterface} object or network interface id string to attach the route to.
@return [nil]
# File lib/aws/ec2/route_table.rb, line 146 def create_route destination_cidr_block, options = {} client.create_route(route_options(destination_cidr_block, options)) nil end
Deletes this route table. The route table must not be associated with a subnet. You can’t delete the main route table. @return [nil]
# File lib/aws/ec2/route_table.rb, line 171 def delete client.delete_route_table(:route_table_id => route_table_id) nil end
@param [String] destination_cidr_block The CIDR block address of the
route to delete.
@return [nil]
# File lib/aws/ec2/route_table.rb, line 163 def delete_route destination_cidr_block client.delete_route(route_options(destination_cidr_block)) nil end
@return [Boolean] Returns true if this is the main (default)
route table.
# File lib/aws/ec2/route_table.rb, line 54 def main? @main = !!associations.find{|a| a.main? } if @main.nil? @main end
Replaces an existing route within a route table in a VPC
. @param (see create_route
) @option (see create_route
) @return [nil]
# File lib/aws/ec2/route_table.rb, line 155 def replace_route destination_cidr_block, options = {} client.replace_route(route_options(destination_cidr_block, options)) nil end
@return [Array<Route>] Returns an array of routes ({Route} objects)
belonging to this route table.
# File lib/aws/ec2/route_table.rb, line 118 def routes route_set.map do |route_details| Route.new(self, route_details) end end
@return [Array<Subnet>] Returns an array of subnets ({Subnet})
that currently associated to this route table.
# 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
@return [VPC] Returns the VPC
this route table belongs to.
# File lib/aws/ec2/route_table.rb, line 60 def vpc VPC.new(vpc_id, :config => config) end
Protected Instance Methods
# File lib/aws/ec2/route_table.rb, line 178 def route_options destination_cidr_block, options = {} client_opts = {} client_opts[:route_table_id] = route_table_id client_opts[:destination_cidr_block] = destination_cidr_block if gateway = options[:internet_gateway] gateway = gateway.id if gateway.is_a?(InternetGateway) client_opts[:gateway_id] = gateway end if instance = options[:instance] instance = instance.id if instance.is_a?(Instance) client_opts[:instance_id] = instance end if interface = options[:network_interface] interface = interface.id if interface.is_a?(NetworkInterface) client_opts[:network_interface_id] = interface end client_opts end