Class: AWS::EC2::Subnet

Inherits:
Resource show all
Includes:
TaggedItem
Defined in:
lib/aws/ec2/subnet.rb

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from TaggedItem

#add_tag, #cached_tags, #clear_tags, #tagging_resource_type, #tags

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(subnet_id, options = {}) ⇒ Subnet

Returns a new instance of Subnet.



31
32
33
34
# File 'lib/aws/ec2/subnet.rb', line 31

def initialize subnet_id, options = {}
  @subnet_id = subnet_id
  super
end

Instance Attribute Details

#availability_zone_nameString (readonly)

Returns the current value of availability_zone_name.

Returns:

  • (String)

    the current value of availability_zone_name



27
28
29
# File 'lib/aws/ec2/subnet.rb', line 27

def availability_zone_name
  @availability_zone_name
end

#available_ip_address_countInteger (readonly)

Returns the current value of available_ip_address_count.

Returns:

  • (Integer)

    the current value of available_ip_address_count



27
28
29
# File 'lib/aws/ec2/subnet.rb', line 27

def available_ip_address_count
  @available_ip_address_count
end

#cidr_blockString (readonly)

Returns the current value of cidr_block.

Returns:

  • (String)

    the current value of cidr_block



27
28
29
# File 'lib/aws/ec2/subnet.rb', line 27

def cidr_block
  @cidr_block
end

#stateSymbol (readonly)

Returns the current value of state.

Returns:

  • (Symbol)

    the current value of state



27
28
29
# File 'lib/aws/ec2/subnet.rb', line 27

def state
  @state
end

#subnet_idString (readonly) Also known as: id

Returns:

  • (String)


37
38
39
# File 'lib/aws/ec2/subnet.rb', line 37

def subnet_id
  @subnet_id
end

#vpc_idString (readonly)

Returns the current value of vpc_id.

Returns:

  • (String)

    the current value of vpc_id



27
28
29
# File 'lib/aws/ec2/subnet.rb', line 27

def vpc_id
  @vpc_id
end

Instance Method Details

#availability_zoneAvailabilityZone

Returns:



135
136
137
# File 'lib/aws/ec2/subnet.rb', line 135

def availability_zone
  AvailabilityZone.new(availability_zone_name, :config => config)
end

#deletenil

Deletes the current subnet. The subnet must be empty before it can be deleted.

Returns:

  • (nil)


154
155
156
157
# File 'lib/aws/ec2/subnet.rb', line 154

def delete
  client.delete_subnet(:subnet_id => subnet_id)
  nil
end

#instancesInstanceCollection

Returns a filtered collection of instances launched in this subnet.

Returns:

  • (InstanceCollection)

    Returns a filtered collection of instances launched in this subnet.



141
142
143
# File 'lib/aws/ec2/subnet.rb', line 141

def instances
  InstanceCollection.new(:config => config).filter('subnet-id', id)
end

#network_aclNetworkACL

Returns the network ACL currently assigned to this subnet.

Returns:

  • (NetworkACL)

    Returns the network ACL currently assigned to this subnet.



67
68
69
# File 'lib/aws/ec2/subnet.rb', line 67

def network_acl
  network_acl_association.network_acl
end

#network_acl=(network_acl) ⇒ Object

Replaces the currently assigned network ACL with the passed one.

Parameters:



74
75
76
# File 'lib/aws/ec2/subnet.rb', line 74

def network_acl= network_acl
  network_acl_association.replace_network_acl(network_acl)
end

#network_acl_associationNetworkACL::Association

Returns the association between this subnet and its network ACL.

Returns:



80
81
82
83
# File 'lib/aws/ec2/subnet.rb', line 80

def network_acl_association
  associations = AWS.memoize { vpc.network_acls.map(&:associations) }.flatten
  associations.first{|a| a.subnet == self }
end

#network_interfacesNetworkInterfaceCollection

Returns a collection that represents all of the network interfaces for this subnet.

Returns:



147
148
149
# File 'lib/aws/ec2/subnet.rb', line 147

def network_interfaces
  NetworkInterfaceCollection.new(:config => config).filter('subnet-id', id)
end

#route_tableRouteTable

Returns the route table currently associated with this subnet.

Returns:

  • (RouteTable)

    Returns the route table currently associated with this subnet.



87
88
89
# File 'lib/aws/ec2/subnet.rb', line 87

def route_table
  route_table_association.route_table
end

#route_table_associationRouteTable::Association

Returns the association between this subnet and its route table.

Returns:



128
129
130
131
# 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) ⇒ RouteTable::Association Also known as: route_table=

Sets the route table for this subnet. If there is already a route table associated with this subnet, that association is replaced.

Parameters:

Returns:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 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

#vpcVPC

Returns the VPC this subnet belongs to.

Returns:

  • (VPC)

    Returns the VPC this subnet belongs to.



61
62
63
# File 'lib/aws/ec2/subnet.rb', line 61

def vpc
  VPC.new(vpc_id, :config => config)
end