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.
-
#default_for_az ⇒ Boolean
Indicates whether this is the default subnet for the Availability Zone.
- #id ⇒ String (also: #subnet_id)
-
#ipv_6_cidr_block_association_set ⇒ Array<Types::SubnetIpv6CidrBlockAssociation>
Information about the IPv6 CIDR blocks associated with the subnet.
-
#map_public_ip_on_launch ⇒ Boolean
Indicates whether instances launched in this subnet receive a public IPv4 address.
-
#owner_id ⇒ String
The ID of the AWS account that owns the subnet.
-
#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
Associations collapse
- #identifiers ⇒ Object deprecated private Deprecated.
- #instances(options = {}) ⇒ Instance::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 = {}, &block) ⇒ 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.
19 20 21 22 23 24 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 19 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @id = extract_id(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() 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.
95 96 97 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 95 def assign_ipv_6_address_on_creation data[:assign_ipv_6_address_on_creation] end |
#availability_zone ⇒ String
The Availability Zone of the subnet.
36 37 38 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 36 def availability_zone data[:availability_zone] end |
#availability_zone_id ⇒ String
The AZ ID of the subnet.
42 43 44 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 42 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.
49 50 51 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 49 def available_ip_address_count data[:available_ip_address_count] end |
#cidr_block ⇒ String
The IPv4 CIDR block assigned to the subnet.
55 56 57 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 55 def cidr_block data[:cidr_block] end |
#create_instances(options = {}) ⇒ Instance::Collection
631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 631 def create_instances( = {}) batch = [] = .merge(subnet_id: @id) resp = @client.run_instances() 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
710 711 712 713 714 715 716 717 718 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 710 def create_network_interface( = {}) = .merge(subnet_id: @id) resp = @client.create_network_interface() NetworkInterface.new( id: resp.data.network_interface.network_interface_id, data: resp.data.network_interface, client: @client ) end |
#create_tags(options = {}) ⇒ Tag::Collection
742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 742 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = @client.() [: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 |
#data ⇒ Types::Subnet
Returns the data for this Aws::EC2::Subnet. Calls Client#describe_subnets if #data_loaded? is ‘false`.
140 141 142 143 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 140 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
148 149 150 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 148 def data_loaded? !!@data end |
#default_for_az ⇒ Boolean
Indicates whether this is the default subnet for the Availability Zone.
62 63 64 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 62 def default_for_az data[:default_for_az] end |
#delete(options = {}) ⇒ EmptyStructure
769 770 771 772 773 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 769 def delete( = {}) = .merge(subnet_id: @id) resp = @client.delete_subnet() resp.data end |
#id ⇒ String Also known as: subnet_id
29 30 31 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 29 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.
1257 1258 1259 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1257 def identifiers { id: @id } end |
#instances(options = {}) ⇒ Instance::Collection
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1062 def instances( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "subnet-id", values: [@id] }]) resp = @client.describe_instances() 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.
101 102 103 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 101 def ipv_6_cidr_block_association_set data[:ipv_6_cidr_block_association_set] 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
130 131 132 133 134 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 130 def load resp = @client.describe_subnets(subnet_ids: [@id]) @data = resp.subnets[0] self end |
#map_public_ip_on_launch ⇒ Boolean
Indicates whether instances launched in this subnet receive a public IPv4 address.
69 70 71 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 69 def map_public_ip_on_launch data[:map_public_ip_on_launch] end |
#network_interfaces(options = {}) ⇒ NetworkInterface::Collection
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1221 def network_interfaces( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "subnet-id", values: [@id] }]) resp = @client.describe_network_interfaces() 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 |
#owner_id ⇒ String
The ID of the AWS account that owns the subnet.
87 88 89 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 87 def owner_id data[:owner_id] end |
#state ⇒ String
The current state of the subnet.
75 76 77 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 75 def state data[:state] end |
#subnet_arn ⇒ String
The Amazon Resource Name (ARN) of the subnet.
113 114 115 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 113 def subnet_arn data[:subnet_arn] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the subnet.
107 108 109 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 107 def data[:tags] end |
#vpc ⇒ Vpc?
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1244 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.
81 82 83 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 81 def vpc_id data[:vpc_id] end |
#wait_until(options = {}, &block) ⇒ 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) {|instance| instance.state.name == 'running' }
## 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
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 230 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::Waiters::Waiter.new().wait({}) end |