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

id[R]

@return [String]

subnet_id[R]

@return [String]

Public Class Methods

new(subnet_id, options = {}) click to toggle source
Calls superclass method 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

availability_zone() click to toggle source

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
delete() click to toggle source

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
instances() click to toggle source

@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
network_acl() click to toggle source

@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
network_acl=(network_acl) click to toggle source

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
network_acl_association() click to toggle source

@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
network_interfaces() click to toggle source

@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
route_table() click to toggle source

@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
route_table=(route_table)
Alias for: set_route_table
route_table_association() click to toggle source

@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
set_route_table(route_table) click to toggle source

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
Also aliased as: route_table=
vpc() click to toggle source

@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