class AWS::EC2::Subnet
@attr_reader [String] vpc_id
@attr_reader [Symbol] state
@attr_reader [String] cidr_block
@attr_reader [Integer] available_ip_address_count
@attr_reader [String] availability_zone_name
Attributes
@return [String]
@return [String]
Public Class Methods
AWS::Core::Resource::new
# File lib/aws/ec2/subnet.rb, line 31 def initialize subnet_id, options = {} @subnet_id = subnet_id super end
Public Instance Methods
See also {#availability_zone_name}. @return [AvailabilityZone]
# File lib/aws/ec2/subnet.rb, line 135 def availability_zone AvailabilityZone.new(availability_zone_name, :config => config) end
Deletes the current subnet. The subnet must be empty before it can be deleted. @return [nil]
# File lib/aws/ec2/subnet.rb, line 154 def delete client.delete_subnet(:subnet_id => subnet_id) nil end
@return [InstanceCollection] Returns a filtered collection of
instances launched in this subnet.
# File lib/aws/ec2/subnet.rb, line 141 def instances InstanceCollection.new(:config => config).filter('subnet-id', id) end
@return [NetworkACL] Returns the network ACL currently assigned
to this subnet.
# File lib/aws/ec2/subnet.rb, line 67 def network_acl network_acl_association.network_acl end
Replaces the currently assigned network ACL with the passed one. @param [NetworkACL,String] network_acl
A {NetworkACL} or network
ACL id to assign to this subnet.
# File lib/aws/ec2/subnet.rb, line 74 def network_acl= network_acl network_acl_association.replace_network_acl(network_acl) end
@return [NetworkACL::Association] Returns the association between
this subnet and its network ACL.
# File lib/aws/ec2/subnet.rb, line 80 def network_acl_association associations = AWS.memoize { vpc.network_acls.map(&:associations) }.flatten associations.find{|a| a.subnet == self } end
@return [NetworkInterfaceCollection] Returns a collection that
represents all of the network interfaces for this subnet.
# File lib/aws/ec2/subnet.rb, line 147 def network_interfaces NetworkInterfaceCollection.new(:config => config).filter('subnet-id', id) end
@return [RouteTable] Returns the route table currently associated
with this subnet.
# File lib/aws/ec2/subnet.rb, line 87 def route_table route_table_association.route_table end
@return [RouteTable::Association] Returns the association between
this subnet and its route table.
# File lib/aws/ec2/subnet.rb, line 128 def route_table_association assocs = AWS.memoize { vpc.route_tables.map(&:associations) }.flatten assocs.find{|a| a.subnet == self } || assocs.find{|a| a.main? } end
Sets the route table for this subnet. If there is already a route table associated with this subnet, that association is replaced.
@param [RouteTable,String] route_table
A {RouteTable} object or
a route table id string.
@return [RouteTable::Association]
# File lib/aws/ec2/subnet.rb, line 100 def set_route_table route_table unless route_table.is_a?(RouteTable) route_table = RouteTable.new(route_table, :config => config) end client_opts = {} client_opts[:route_table_id] = route_table.id assoc = route_table_association if assoc.main? client_opts[:subnet_id] = subnet_id response = client.associate_route_table(client_opts) association_id = response.association_id else client_opts[:association_id] = assoc.association_id resp = client.replace_route_table_association(client_opts) association_id = resp.new_association_id end RouteTable::Association.new(route_table, association_id, subnet_id) end
@return [VPC] Returns the VPC
this subnet belongs to.
# File lib/aws/ec2/subnet.rb, line 61 def vpc VPC.new(vpc_id, :config => config) end