Class: Aws::EC2::Subnet
- Inherits:
-
Object
- Object
- Aws::EC2::Subnet
- Defined in:
- gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#assign_ipv_6_address_on_creation ⇒ Boolean
Indicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives an IPv6 address.
-
#availability_zone ⇒ String
The Availability Zone of the subnet.
-
#availability_zone_id ⇒ String
The AZ ID of the subnet.
-
#available_ip_address_count ⇒ Integer
The number of unused private IPv4 addresses in the subnet.
-
#block_public_access_states ⇒ Types::BlockPublicAccessStates
The state of VPC Block Public Access (BPA).
-
#cidr_block ⇒ String
The IPv4 CIDR block assigned to the subnet.
-
#customer_owned_ipv_4_pool ⇒ String
The customer-owned IPv4 address pool associated with the subnet.
-
#default_for_az ⇒ Boolean
Indicates whether this is the default subnet for the Availability Zone.
-
#enable_dns_64 ⇒ Boolean
Indicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations.
-
#enable_lni_at_device_index ⇒ Integer
Indicates the device position for local network interfaces in this subnet.
-
#id ⇒ String
(also: #subnet_id)
-
#ipv_6_cidr_block_association_set ⇒ Array<Types::SubnetIpv6CidrBlockAssociation>
Information about the IPv6 CIDR blocks associated with the subnet.
-
#ipv_6_native ⇒ Boolean
Indicates whether this is an IPv6 only subnet.
-
#map_customer_owned_ip_on_launch ⇒ Boolean
Indicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives a customer-owned IPv4 address.
-
#map_public_ip_on_launch ⇒ Boolean
Indicates whether instances launched in this subnet receive a public IPv4 address.
-
#network_firewall_connectivity_type ⇒ String
The internet connectivity treatment that the Automated Internet Firewall applies to the subnet.
-
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
-
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the subnet.
-
#private_dns_name_options_on_launch ⇒ Types::PrivateDnsNameOptionsOnLaunch
The type of hostnames to assign to instances in the subnet at launch.
-
#state ⇒ String
The current state of the subnet.
-
#subnet_arn ⇒ String
The Amazon Resource Name (ARN) of the subnet.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the subnet.
-
#type ⇒ String
Indicates if this is a subnet used with Amazon Elastic VMware Service (EVS).
-
#vpc_id ⇒ String
The ID of the VPC the subnet is in.
Actions collapse
-
#create_instances(options = {}) ⇒ Instance::Collection
-
#create_network_interface(options = {}) ⇒ NetworkInterface
-
#create_tags(options = {}) ⇒ Tag::Collection
-
#delete(options = {}) ⇒ EmptyStructure
-
#delete_tags(options = {}) ⇒ Tag::Collection
Associations collapse
-
#instances(options = {}) ⇒ Instance::Collection
-
#nat_gateways(options = {}) ⇒ NatGateway::Collection
-
#network_interfaces(options = {}) ⇒ NetworkInterface::Collection
-
#vpc ⇒ Vpc?
Instance Method Summary collapse
-
#client ⇒ Client
-
#data ⇒ Types::Subnet
Returns the data for this Subnet.
-
#data_loaded? ⇒ Boolean
Returns
trueif this resource is loaded. -
#initialize(*args) ⇒ Subnet
constructor
A new instance of Subnet.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
Constructor Details
#initialize(id, options = {}) ⇒ Subnet #initialize(options = {}) ⇒ Subnet
Returns a new instance of Subnet.
22 23 24 25 26 27 28 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 22 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @id = extract_id(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#assign_ipv_6_address_on_creation ⇒ Boolean
Indicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives an IPv6 address.
76 77 78 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 76 def assign_ipv_6_address_on_creation data[:assign_ipv_6_address_on_creation] end |
#availability_zone ⇒ String
The Availability Zone of the subnet.
214 215 216 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 214 def availability_zone data[:availability_zone] end |
#availability_zone_id ⇒ String
The AZ ID of the subnet.
40 41 42 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 40 def availability_zone_id data[:availability_zone_id] end |
#available_ip_address_count ⇒ Integer
The number of unused private IPv4 addresses in the subnet. The IPv4 addresses for any stopped instances are considered unavailable.
208 209 210 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 208 def available_ip_address_count data[:available_ip_address_count] end |
#block_public_access_states ⇒ Types::BlockPublicAccessStates
The state of VPC Block Public Access (BPA).
128 129 130 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 128 def block_public_access_states data[:block_public_access_states] end |
#cidr_block ⇒ String
The IPv4 CIDR block assigned to the subnet.
201 202 203 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 201 def cidr_block data[:cidr_block] end |
#client ⇒ Client
244 245 246 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 244 def client @client end |
#create_instances(options = {}) ⇒ Instance::Collection
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 943 def create_instances( = {}) batch = [] = .merge(subnet_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.run_instances() end resp.data.instances.each do |i| batch << Instance.new( id: i.instance_id, data: i, client: @client ) end Instance::Collection.new([batch], size: batch.size) end |
#create_network_interface(options = {}) ⇒ NetworkInterface
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1130 def create_network_interface( = {}) = .merge(subnet_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.create_network_interface() end NetworkInterface.new( id: resp.data.network_interface.network_interface_id, data: resp.data.network_interface, client: @client ) end |
#create_tags(options = {}) ⇒ Tag::Collection
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1164 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end [:tags].each do |t| batch << Tag.new( resource_id: @id, key: t[:key], value: t[:value], client: @client ) end Tag::Collection.new([batch], size: batch.size) end |
#customer_owned_ipv_4_pool ⇒ String
The customer-owned IPv4 address pool associated with the subnet.
62 63 64 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 62 def customer_owned_ipv_4_pool data[:customer_owned_ipv_4_pool] end |
#data ⇒ Types::Subnet
Returns the data for this Aws::EC2::Subnet. Calls
Client#describe_subnets if #data_loaded? is false.
266 267 268 269 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 266 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
274 275 276 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 274 def data_loaded? !!@data end |
#default_for_az ⇒ Boolean
Indicates whether this is the default subnet for the Availability Zone.
221 222 223 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 221 def default_for_az data[:default_for_az] end |
#delete(options = {}) ⇒ EmptyStructure
1240 1241 1242 1243 1244 1245 1246 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1240 def delete( = {}) = .merge(subnet_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_subnet() end resp.data end |
#delete_tags(options = {}) ⇒ Tag::Collection
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1211 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end [:tags].each do |t| batch << Tag.new( resource_id: @id, key: t[:key], value: t[:value], client: @client ) end Tag::Collection.new([batch], size: batch.size) end |
#enable_dns_64 ⇒ Boolean
Indicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations.
108 109 110 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 108 def enable_dns_64 data[:enable_dns_64] end |
#enable_lni_at_device_index ⇒ Integer
Indicates the device position for local network interfaces in this
subnet. For example, 1 indicates local network interfaces in this
subnet are the secondary network interface (eth1).
48 49 50 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 48 def enable_lni_at_device_index data[:enable_lni_at_device_index] end |
#id ⇒ String Also known as: subnet_id
33 34 35 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 33 def id @id end |
#instances(options = {}) ⇒ Instance::Collection
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1726 def instances( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "subnet-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_instances() end resp.each_page do |page| batch = [] page.data.reservations.each do |r| r.instances.each do |i| batch << Instance.new( id: i.instance_id, data: i, client: @client ) end end y.yield(batch) end end Instance::Collection.new(batches) end |
#ipv_6_cidr_block_association_set ⇒ Array<Types::SubnetIpv6CidrBlockAssociation>
Information about the IPv6 CIDR blocks associated with the subnet.
82 83 84 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 82 def ipv_6_cidr_block_association_set data[:ipv_6_cidr_block_association_set] end |
#ipv_6_native ⇒ Boolean
Indicates whether this is an IPv6 only subnet.
114 115 116 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 114 def ipv_6_native data[:ipv_6_native] end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::EC2::Subnet.
Returns self making it possible to chain methods.
subnet.reload.data
254 255 256 257 258 259 260 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 254 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_subnets(subnet_ids: [@id]) end @data = resp.subnets[0] self end |
#map_customer_owned_ip_on_launch ⇒ Boolean
Indicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives a customer-owned IPv4 address.
56 57 58 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 56 def map_customer_owned_ip_on_launch data[:map_customer_owned_ip_on_launch] end |
#map_public_ip_on_launch ⇒ Boolean
Indicates whether instances launched in this subnet receive a public IPv4 address.
Amazon Web Services charges for all public IPv4 addresses, including public IPv4 addresses associated with running instances and Elastic IP addresses. For more information, see the Public IPv4 Address tab on the Amazon VPC pricing page.
237 238 239 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 237 def map_public_ip_on_launch data[:map_public_ip_on_launch] end |
#nat_gateways(options = {}) ⇒ NatGateway::Collection
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1794 def nat_gateways( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filter: [{ name: "subnet-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_nat_gateways() end resp.each_page do |page| batch = [] page.data.nat_gateways.each do |n| batch << NatGateway.new( id: n.nat_gateway_id, data: n, client: @client ) end y.yield(batch) end end NatGateway::Collection.new(batches) end |
#network_firewall_connectivity_type ⇒ String
The internet connectivity treatment that the Automated Internet Firewall applies to the subnet. The response includes this value only if the subnet is in a VPC that has a firewall. Possible values:
az-unsupported: The firewall doesn't support the subnet's Availability Zone, so it doesn't inspect traffic for the subnet.bidirectional: Provides bidirectional internet connectivity to every network interface that has a public IP association. Any network interface without a public IP cannot communicate with the internet unless a NAT device is explicitly inserted in the path. All inbound and outbound traffic is inspected against your firewall rules.exclude: The firewall doesn't inspect traffic for the subnet. The subnet bypasses the firewall, and its traffic passes directly through the internet gateway.flexible: Sets the connectivity for each network interface in the subnet based on whether it is associated with a public IP address. A network interface with a public IP address gets bidirectional internet connectivity. A network interface without a public IP address gets outbound-only connectivity. All traffic is inspected against your firewall rules.outbound-only: Provides egress-only connectivity for all network interfaces in the subnet. All outbound traffic and inbound responses are inspected against your firewall rules. Unsolicited inbound connections are dropped. For IPv4 traffic, the firewall performs NAT.
176 177 178 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 176 def network_firewall_connectivity_type data[:network_firewall_connectivity_type] end |
#network_interfaces(options = {}) ⇒ NetworkInterface::Collection
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1972 def network_interfaces( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "subnet-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_network_interfaces() end resp.each_page do |page| batch = [] page.data.network_interfaces.each do |n| batch << NetworkInterface.new( id: n.network_interface_id, data: n, client: @client ) end y.yield(batch) end end NetworkInterface::Collection.new(batches) end |
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
100 101 102 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 100 def outpost_arn data[:outpost_arn] end |
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the subnet.
68 69 70 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 68 def owner_id data[:owner_id] end |
#private_dns_name_options_on_launch ⇒ Types::PrivateDnsNameOptionsOnLaunch
The type of hostnames to assign to instances in the subnet at launch. An instance hostname is based on the IPv4 address or ID of the instance.
122 123 124 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 122 def data[:private_dns_name_options_on_launch] end |
#state ⇒ String
The current state of the subnet.
failed: The underlying infrastructure to support the subnet failed to provision as expected.failed-insufficient-capacity: The underlying infrastructure to support the subnet failed to provision due to a shortage of EC2 instance capacity.
189 190 191 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 189 def state data[:state] end |
#subnet_arn ⇒ String
The Amazon Resource Name (ARN) of the subnet.
94 95 96 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 94 def subnet_arn data[:subnet_arn] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the subnet.
88 89 90 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 88 def data[:tags] end |
#type ⇒ String
Indicates if this is a subnet used with Amazon Elastic VMware Service
(EVS). Possible values are Elastic VMware Service or no value. For
more information about Amazon EVS, see Amazon Elastic VMware
Service API Reference .
141 142 143 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 141 def type data[:type] end |
#vpc ⇒ Vpc?
1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 1997 def vpc if data[:vpc_id] Vpc.new( id: data[:vpc_id], client: @client ) else nil end end |
#vpc_id ⇒ String
The ID of the VPC the subnet is in.
195 196 197 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 195 def vpc_id data[:vpc_id] end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::EC2::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged.
Waiter polls an API operation until a resource enters a desired state.
Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
Example
instance.wait_until(max_attempts:10, delay:5) do |instance|
instance.state.name == 'running'
end
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success or :failure from these callbacks,
it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/subnet.rb', line 358 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |