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.
-
#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.
-
#state ⇒ String
The current state 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)
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.
84 85 86 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 84 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 |
#available_ip_address_count ⇒ Integer
The number of unused private IPv4 addresses in the subnet. Note that the IPv4 addresses for any stopped instances are considered unavailable.
44 45 46 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 44 def available_ip_address_count data.available_ip_address_count end |
#cidr_block ⇒ String
The IPv4 CIDR block assigned to the subnet.
50 51 52 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 50 def cidr_block data.cidr_block end |
#create_instances(options = {}) ⇒ Instance::Collection
409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 409 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
488 489 490 491 492 493 494 495 496 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 488 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
520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 520 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`.
123 124 125 126 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 123 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
131 132 133 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 131 def data_loaded? !!@data end |
#default_for_az ⇒ Boolean
Indicates whether this is the default subnet for the Availability Zone.
57 58 59 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 57 def default_for_az data.default_for_az end |
#delete(options = {}) ⇒ EmptyStructure
547 548 549 550 551 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 547 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.
1040 1041 1042 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1040 def identifiers { id: @id } end |
#instances(options = {}) ⇒ Instance::Collection
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 840 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.
90 91 92 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 90 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
113 114 115 116 117 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 113 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.
64 65 66 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 64 def map_public_ip_on_launch data.map_public_ip_on_launch end |
#network_interfaces(options = {}) ⇒ NetworkInterface::Collection
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1006 def network_interfaces( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "subnet-id", values: [@id] }]) resp = @client.describe_network_interfaces() resp.data.network_interfaces.each do |n| batch << NetworkInterface.new( id: n.network_interface_id, data: n, client: @client ) end y.yield(batch) end NetworkInterface::Collection.new(batches) end |
#state ⇒ String
The current state of the subnet.
70 71 72 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 70 def state data.state end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the subnet.
96 97 98 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 96 def data. end |
#vpc ⇒ Vpc?
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 1027 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.
76 77 78 |
# File 'lib/aws-sdk-ec2/subnet.rb', line 76 def vpc_id data.vpc_id end |