1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
# Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
module AWS
class EC2
class RouteTable < Resource
# Represents the association between a {RouteTable} and a {Subnet}.
#
# You can get a route table association 2 ways:
#
# * enumerating associations from a route table
# * Asking a subnet for its route table association
#
# ## Enumerating Associations
#
# Given a route table:
#
# route_table.associations.each do |assoc|
# if assoc.main? # main association does not have a subnet
# puts "#{assoc.id} : main association"
# else
# puts "#{assoc.id} : #{assoc.subnet.id}"
# end
# end
#
# ## Getting a Subnet Route Table Association
#
# All subnets are associated with a route table. If the association
# was never explicitly created, then they are associated by default
# with the main route table.
#
# subnet.route_table_association #=> AWS::EC2::RouteTable::Association
#
# subnet.route_table_association.main? #=> true/false
#
# ## Creating and Replacing a Route Table Association
#
# To replace a route table association start at the subnet end:
#
# subnet.route_table = some_other_route_table
#
# If this route table is associated (by default) to the main route
# table via the main (default) association a new association is created.
# If it was previously associated directly to a different route table
# then that association will be repalced.
#
# ## Deleting an Association
#
# You can delete all but the main route table association. When you
# delete an association, the subnet becomes associated with the
# main route table.
#
# # delete all explicit route table associations -- as a result
# # all subnets will default to the main route table
# vpc.subnets.each do |subnet|
# assoc = subnet.route_table_association
# assoc.delete unless assoc.main?
# end
#
class Association
# @api private
def initialize route_table, association_id, subnet_id
@route_table = route_table
@association_id = association_id
if subnet_id
@main = false
@subnet = Subnet.new(subnet_id,
:config => route_table.config)
else
@main = true
end
end
# @return [String] An identifier representing the association
# between the network ACL and subnet.
attr_reader :association_id
alias_method :id, :association_id
# @return [RouteTable]
attr_reader :route_table
# @return [Subnet,nil] Returns the subnet this association belongs.
# If this is the main (default) association, then this method
# returns nil.
attr_reader :subnet
# @return [Boolean] Returns true if this association is the main
# (default) association for all subnets within this route table's
# VPC.
attr_reader :main
alias_method :main?, :main
# Deletes the association between the route table and the subnet
# @return [nil]
def delete
route_table.client.disassociate_route_table(
:association_id => association_id)
nil
end
alias_method :disassociate, :delete
end
end
end
end
|