Class: AWS::EC2::Subnet
- Inherits:
-
Resource
- Object
- Core::Resource
- Resource
- AWS::EC2::Subnet
- Includes:
- TaggedItem
- Defined in:
- lib/aws/ec2/subnet.rb
Instance Attribute Summary collapse
-
#availability_zone_name ⇒ String
readonly
The current value of availability_zone_name.
-
#available_ip_address_count ⇒ Integer
readonly
The current value of available_ip_address_count.
-
#cidr_block ⇒ String
readonly
The current value of cidr_block.
-
#state ⇒ Symbol
readonly
The current value of state.
- #subnet_id ⇒ String (also: #id) readonly
-
#vpc_id ⇒ String
readonly
The current value of vpc_id.
Instance Method Summary collapse
-
#availability_zone ⇒ AvailabilityZone
See also #availability_zone_name.
-
#delete ⇒ nil
Deletes the current subnet.
-
#initialize(subnet_id, options = {}) ⇒ Subnet
constructor
A new instance of Subnet.
-
#instances ⇒ InstanceCollection
Returns a filtered collection of instances launched in this subnet.
-
#network_acl ⇒ NetworkACL
Returns the network ACL currently assigned to this subnet.
-
#network_acl=(network_acl) ⇒ Object
Replaces the currently assigned network ACL with the passed one.
-
#network_acl_association ⇒ NetworkACL::Association
Returns the association between this subnet and its network ACL.
-
#network_interfaces ⇒ NetworkInterfaceCollection
Returns a collection that represents all of the network interfaces for this subnet.
-
#route_table ⇒ RouteTable
Returns the route table currently associated with this subnet.
-
#route_table_association ⇒ RouteTable::Association
Returns the association between this subnet and its route table.
-
#set_route_table(route_table) ⇒ RouteTable::Association
(also: #route_table=)
Sets the route table for this subnet.
-
#vpc ⇒ VPC
Returns the VPC this subnet belongs to.
Methods included from TaggedItem
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, = {} @subnet_id = subnet_id super end |
Instance Attribute Details
#availability_zone_name ⇒ String (readonly)
Returns 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_count ⇒ Integer (readonly)
Returns 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_block ⇒ String (readonly)
Returns the current value of cidr_block.
27 28 29 |
# File 'lib/aws/ec2/subnet.rb', line 27 def cidr_block @cidr_block end |
#state ⇒ Symbol (readonly)
Returns the current value of state.
27 28 29 |
# File 'lib/aws/ec2/subnet.rb', line 27 def state @state end |
#subnet_id ⇒ String (readonly) Also known as: id
37 38 39 |
# File 'lib/aws/ec2/subnet.rb', line 37 def subnet_id @subnet_id end |
#vpc_id ⇒ String (readonly)
Returns 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_zone ⇒ AvailabilityZone
See also #availability_zone_name.
135 136 137 |
# File 'lib/aws/ec2/subnet.rb', line 135 def availability_zone AvailabilityZone.new(availability_zone_name, :config => config) end |
#delete ⇒ nil
Deletes the current subnet. The subnet must be empty before it can be deleted.
154 155 156 157 |
# File 'lib/aws/ec2/subnet.rb', line 154 def delete client.delete_subnet(:subnet_id => subnet_id) nil end |
#instances ⇒ 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_acl ⇒ 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.
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_association ⇒ NetworkACL::Association
Returns the association between this subnet and its network ACL.
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_interfaces ⇒ NetworkInterfaceCollection
Returns a collection that represents all of the network interfaces for this subnet.
147 148 149 |
# File 'lib/aws/ec2/subnet.rb', line 147 def network_interfaces NetworkInterfaceCollection.new(:config => config).filter('subnet-id', id) end |
#route_table ⇒ 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_association ⇒ RouteTable::Association
Returns the association between this subnet and its route table.
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.
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 |