Class: Aws::EC2::Subnet
- Inherits:
-
Object
- Object
- Aws::EC2::Subnet
- Extended by:
- Deprecations
- Defined in:
- 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.
-
#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.
-
#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.
-
#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
- #identifiers ⇒ Object deprecated private Deprecated.
- #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 ‘true` if 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 '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.
121 122 123 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 121 def assign_ipv_6_address_on_creation data[:assign_ipv_6_address_on_creation] end |
#availability_zone ⇒ String
The Availability Zone of the subnet.
40 41 42 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 40 def availability_zone data[:availability_zone] end |
#availability_zone_id ⇒ String
The AZ ID of the subnet.
46 47 48 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 46 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.
53 54 55 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 53 def available_ip_address_count data[:available_ip_address_count] end |
#cidr_block ⇒ String
The IPv4 CIDR block assigned to the subnet.
59 60 61 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 59 def cidr_block data[:cidr_block] end |
#create_instances(options = {}) ⇒ Instance::Collection
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 857 def create_instances( = {}) batch = [] = .merge(subnet_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') 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
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1034 def create_network_interface( = {}) = .merge(subnet_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') 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
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1068 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.feature('resource') 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.
95 96 97 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 95 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`.
196 197 198 199 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 196 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
204 205 206 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 204 def data_loaded? !!@data end |
#default_for_az ⇒ Boolean
Indicates whether this is the default subnet for the Availability Zone.
66 67 68 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 66 def default_for_az data[:default_for_az] end |
#delete(options = {}) ⇒ EmptyStructure
1144 1145 1146 1147 1148 1149 1150 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1144 def delete( = {}) = .merge(subnet_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.delete_subnet() end resp.data end |
#delete_tags(options = {}) ⇒ Tag::Collection
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1115 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.feature('resource') 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.
153 154 155 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 153 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).
74 75 76 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 74 def enable_lni_at_device_index data[:enable_lni_at_device_index] end |
#id ⇒ String Also known as: subnet_id
33 34 35 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 33 def id @id end |
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1870 1871 1872 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1870 def identifiers { id: @id } end |
#instances(options = {}) ⇒ Instance::Collection
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1602 def instances( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "subnet-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') 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.
127 128 129 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 127 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.
159 160 161 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 159 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
184 185 186 187 188 189 190 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 184 def load resp = Aws::Plugins::UserAgent.feature('resource') 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.
89 90 91 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 89 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.
81 82 83 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 81 def map_public_ip_on_launch data[:map_public_ip_on_launch] end |
#nat_gateways(options = {}) ⇒ NatGateway::Collection
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1670 def nat_gateways( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filter: [{ name: "subnet-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') 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_interfaces(options = {}) ⇒ NetworkInterface::Collection
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1832 def network_interfaces( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "subnet-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') 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.
145 146 147 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 145 def outpost_arn data[:outpost_arn] end |
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the subnet.
113 114 115 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 113 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.
167 168 169 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 167 def data[:private_dns_name_options_on_launch] end |
#state ⇒ String
The current state of the subnet.
101 102 103 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 101 def state data[:state] end |
#subnet_arn ⇒ String
The Amazon Resource Name (ARN) of the subnet.
139 140 141 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 139 def subnet_arn data[:subnet_arn] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the subnet.
133 134 135 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 133 def data[:tags] end |
#vpc ⇒ Vpc?
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1857 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.
107 108 109 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 107 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
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 288 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.feature('resource') do Aws::Waiters::Waiter.new().wait({}) end end |