Class: Aws::EC2::Vpc
- Inherits:
-
Object
- Object
- Aws::EC2::Vpc
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-ec2/vpc.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#cidr_block ⇒ String
The primary IPv4 CIDR block for the VPC.
-
#cidr_block_association_set ⇒ Array<Types::VpcCidrBlockAssociation>
Information about the IPv4 CIDR blocks associated with the VPC.
-
#dhcp_options_id ⇒ String
The ID of the set of DHCP options you’ve associated with the VPC (or ‘default` if the default options are associated with the VPC).
- #id ⇒ String (also: #vpc_id)
-
#instance_tenancy ⇒ String
The allowed tenancy of instances launched into the VPC.
-
#ipv_6_cidr_block_association_set ⇒ Array<Types::VpcIpv6CidrBlockAssociation>
Information about the IPv6 CIDR blocks associated with the VPC.
-
#is_default ⇒ Boolean
Indicates whether the VPC is the default VPC.
-
#state ⇒ String
The current state of the VPC.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the VPC.
Actions collapse
- #associate_dhcp_options(options = {}) ⇒ EmptyStructure
- #attach_classic_link_instance(options = {}) ⇒ Types::AttachClassicLinkVpcResult
- #attach_internet_gateway(options = {}) ⇒ EmptyStructure
- #create_network_acl(options = {}) ⇒ NetworkAcl
- #create_route_table(options = {}) ⇒ RouteTable
- #create_security_group(options = {}) ⇒ SecurityGroup
- #create_subnet(options = {}) ⇒ Subnet
- #create_tags(options = {}) ⇒ Tag::Collection
- #delete(options = {}) ⇒ EmptyStructure
- #describe_attribute(options = {}) ⇒ Types::DescribeVpcAttributeResult
- #detach_classic_link_instance(options = {}) ⇒ Types::DetachClassicLinkVpcResult
- #detach_internet_gateway(options = {}) ⇒ EmptyStructure
- #disable_classic_link(options = {}) ⇒ Types::DisableVpcClassicLinkResult
- #enable_classic_link(options = {}) ⇒ Types::EnableVpcClassicLinkResult
- #modify_attribute(options = {}) ⇒ EmptyStructure
- #request_vpc_peering_connection(options = {}) ⇒ VpcPeeringConnection
Associations collapse
- #accepted_vpc_peering_connections(options = {}) ⇒ VpcPeeringConnection::Collection
- #dhcp_options ⇒ DhcpOptions?
- #identifiers ⇒ Object deprecated private Deprecated.
- #instances(options = {}) ⇒ Instance::Collection
- #internet_gateways(options = {}) ⇒ InternetGateway::Collection
- #network_acls(options = {}) ⇒ NetworkAcl::Collection
- #network_interfaces(options = {}) ⇒ NetworkInterface::Collection
- #requested_vpc_peering_connections(options = {}) ⇒ VpcPeeringConnection::Collection
- #route_tables(options = {}) ⇒ RouteTable::Collection
- #security_groups(options = {}) ⇒ SecurityGroup::Collection
- #subnets(options = {}) ⇒ Subnet::Collection
Instance Method Summary collapse
- #client ⇒ Client
-
#data ⇒ Types::Vpc
Returns the data for this Vpc.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the Vpc exists.
-
#initialize(*args) ⇒ Vpc
constructor
A new instance of Vpc.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}, &block) ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
- #wait_until_available(options = {}) ⇒ Vpc
- #wait_until_exists(options = {}) ⇒ Vpc
Constructor Details
#initialize(id, options = {}) ⇒ Vpc #initialize(options = {}) ⇒ Vpc
Returns a new instance of Vpc.
19 20 21 22 23 24 |
# File 'lib/aws-sdk-ec2/vpc.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
#accepted_vpc_peering_connections(options = {}) ⇒ VpcPeeringConnection::Collection
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 753 def accepted_vpc_peering_connections( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "accepter-vpc-info.vpc-id", values: [@id] }]) resp = @client.describe_vpc_peering_connections() resp.data.vpc_peering_connections.each do |v| batch << VpcPeeringConnection.new( id: v.vpc_peering_connection_id, data: v, client: @client ) end y.yield(batch) end VpcPeeringConnection::Collection.new(batches) end |
#associate_dhcp_options(options = {}) ⇒ EmptyStructure
279 280 281 282 283 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 279 def ( = {}) = .merge(vpc_id: @id) resp = @client.() resp.data end |
#attach_classic_link_instance(options = {}) ⇒ Types::AttachClassicLinkVpcResult
305 306 307 308 309 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 305 def attach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = @client.attach_classic_link_vpc() resp.data end |
#attach_internet_gateway(options = {}) ⇒ EmptyStructure
326 327 328 329 330 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 326 def attach_internet_gateway( = {}) = .merge(vpc_id: @id) resp = @client.attach_internet_gateway() resp.data end |
#cidr_block ⇒ String
The primary IPv4 CIDR block for the VPC.
36 37 38 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 36 def cidr_block data[:cidr_block] end |
#cidr_block_association_set ⇒ Array<Types::VpcCidrBlockAssociation>
Information about the IPv4 CIDR blocks associated with the VPC.
67 68 69 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 67 def cidr_block_association_set data[:cidr_block_association_set] end |
#create_network_acl(options = {}) ⇒ NetworkAcl
344 345 346 347 348 349 350 351 352 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 344 def create_network_acl( = {}) = .merge(vpc_id: @id) resp = @client.create_network_acl() NetworkAcl.new( id: resp.data.network_acl.network_acl_id, data: resp.data.network_acl, client: @client ) end |
#create_route_table(options = {}) ⇒ RouteTable
366 367 368 369 370 371 372 373 374 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 366 def create_route_table( = {}) = .merge(vpc_id: @id) resp = @client.create_route_table() RouteTable.new( id: resp.data.route_table.route_table_id, data: resp.data.route_table, client: @client ) end |
#create_security_group(options = {}) ⇒ SecurityGroup
408 409 410 411 412 413 414 415 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 408 def create_security_group( = {}) = .merge(vpc_id: @id) resp = @client.create_security_group() SecurityGroup.new( id: resp.data.group_id, client: @client ) end |
#create_subnet(options = {}) ⇒ Subnet
444 445 446 447 448 449 450 451 452 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 444 def create_subnet( = {}) = .merge(vpc_id: @id) resp = @client.create_subnet() Subnet.new( id: resp.data.subnet.subnet_id, data: resp.data.subnet, client: @client ) end |
#create_tags(options = {}) ⇒ Tag::Collection
476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 476 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::Vpc
Returns the data for this Aws::EC2::Vpc. Calls Client#describe_vpcs if #data_loaded? is ‘false`.
106 107 108 109 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 106 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
114 115 116 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 114 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
503 504 505 506 507 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 503 def delete( = {}) = .merge(vpc_id: @id) resp = @client.delete_vpc() resp.data end |
#describe_attribute(options = {}) ⇒ Types::DescribeVpcAttributeResult
524 525 526 527 528 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 524 def describe_attribute( = {}) = .merge(vpc_id: @id) resp = @client.describe_vpc_attribute() resp.data end |
#detach_classic_link_instance(options = {}) ⇒ Types::DetachClassicLinkVpcResult
545 546 547 548 549 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 545 def detach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = @client.detach_classic_link_vpc() resp.data end |
#detach_internet_gateway(options = {}) ⇒ EmptyStructure
566 567 568 569 570 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 566 def detach_internet_gateway( = {}) = .merge(vpc_id: @id) resp = @client.detach_internet_gateway() resp.data end |
#dhcp_options ⇒ DhcpOptions?
774 775 776 777 778 779 780 781 782 783 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 774 def if data[:dhcp_options_id] DhcpOptions.new( id: data[:dhcp_options_id], client: @client ) else nil end end |
#dhcp_options_id ⇒ String
The ID of the set of DHCP options you’ve associated with the VPC (or ‘default` if the default options are associated with the VPC).
43 44 45 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 43 def data[:dhcp_options_id] end |
#disable_classic_link(options = {}) ⇒ Types::DisableVpcClassicLinkResult
584 585 586 587 588 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 584 def disable_classic_link( = {}) = .merge(vpc_id: @id) resp = @client.disable_vpc_classic_link() resp.data end |
#enable_classic_link(options = {}) ⇒ Types::EnableVpcClassicLinkResult
602 603 604 605 606 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 602 def enable_classic_link( = {}) = .merge(vpc_id: @id) resp = @client.enable_vpc_classic_link() resp.data end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the Vpc exists.
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 121 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#id ⇒ String Also known as: vpc_id
29 30 31 |
# File 'lib/aws-sdk-ec2/vpc.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.
1863 1864 1865 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1863 def identifiers { id: @id } end |
#instance_tenancy ⇒ String
The allowed tenancy of instances launched into the VPC.
55 56 57 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 55 def instance_tenancy data[:instance_tenancy] end |
#instances(options = {}) ⇒ Instance::Collection
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1070 def instances( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-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 |
#internet_gateways(options = {}) ⇒ InternetGateway::Collection
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1144 def internet_gateways( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "attachment.vpc-id", values: [@id] }]) resp = @client.describe_internet_gateways() resp.data.internet_gateways.each do |i| batch << InternetGateway.new( id: i.internet_gateway_id, data: i, client: @client ) end y.yield(batch) end InternetGateway::Collection.new(batches) end |
#ipv_6_cidr_block_association_set ⇒ Array<Types::VpcIpv6CidrBlockAssociation>
Information about the IPv6 CIDR blocks associated with the VPC.
61 62 63 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 61 def ipv_6_cidr_block_association_set data[:ipv_6_cidr_block_association_set] end |
#is_default ⇒ Boolean
Indicates whether the VPC is the default VPC.
73 74 75 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 73 def is_default data[:is_default] end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::EC2::Vpc. Returns ‘self` making it possible to chain methods.
vpc.reload.data
96 97 98 99 100 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 96 def load resp = @client.describe_vpcs(vpc_ids: [@id]) @data = resp.vpcs[0] self end |
#modify_attribute(options = {}) ⇒ EmptyStructure
638 639 640 641 642 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 638 def modify_attribute( = {}) = .merge(vpc_id: @id) resp = @client.modify_vpc_attribute() resp.data end |
#network_acls(options = {}) ⇒ NetworkAcl::Collection
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1248 def network_acls( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = @client.describe_network_acls() resp.data.network_acls.each do |n| batch << NetworkAcl.new( id: n.network_acl_id, data: n, client: @client ) end y.yield(batch) end NetworkAcl::Collection.new(batches) end |
#network_interfaces(options = {}) ⇒ NetworkInterface::Collection
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1410 def network_interfaces( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "vpc-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 |
#request_vpc_peering_connection(options = {}) ⇒ VpcPeeringConnection
671 672 673 674 675 676 677 678 679 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 671 def request_vpc_peering_connection( = {}) = .merge(vpc_id: @id) resp = @client.create_vpc_peering_connection() VpcPeeringConnection.new( id: resp.data.vpc_peering_connection.vpc_peering_connection_id, data: resp.data.vpc_peering_connection, client: @client ) end |
#requested_vpc_peering_connections(options = {}) ⇒ VpcPeeringConnection::Collection
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1500 def requested_vpc_peering_connections( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "requester-vpc-info.vpc-id", values: [@id] }]) resp = @client.describe_vpc_peering_connections() resp.data.vpc_peering_connections.each do |v| batch << VpcPeeringConnection.new( id: v.vpc_peering_connection_id, data: v, client: @client ) end y.yield(batch) end VpcPeeringConnection::Collection.new(batches) end |
#route_tables(options = {}) ⇒ RouteTable::Collection
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1615 def route_tables( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = @client.describe_route_tables() resp.data.route_tables.each do |r| batch << RouteTable.new( id: r.route_table_id, data: r, client: @client ) end y.yield(batch) end RouteTable::Collection.new(batches) end |
#security_groups(options = {}) ⇒ SecurityGroup::Collection
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1749 def security_groups( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = @client.describe_security_groups() resp.data.security_groups.each do |s| batch << SecurityGroup.new( id: s.group_id, data: s, client: @client ) end y.yield(batch) end SecurityGroup::Collection.new(batches) end |
#state ⇒ String
The current state of the VPC.
49 50 51 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 49 def state data[:state] end |
#subnets(options = {}) ⇒ Subnet::Collection
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1841 def subnets( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = @client.describe_subnets() resp.data.subnets.each do |s| batch << Subnet.new( id: s.subnet_id, data: s, client: @client ) end y.yield(batch) end Subnet::Collection.new(batches) end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the VPC.
79 80 81 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 79 def data[:tags] 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
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 244 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 |
#wait_until_available(options = {}) ⇒ Vpc
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 138 def wait_until_available( = {}) , params = () waiter = Waiters::VpcAvailable.new() yield_waiter_and_warn(waiter, &Proc.new) if block_given? waiter.wait(params.merge(vpc_ids: [@id])) Vpc.new({ id: @id, client: @client }) end |
#wait_until_exists(options = {}) ⇒ Vpc
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 155 def wait_until_exists( = {}) , params = () waiter = Waiters::VpcExists.new() yield_waiter_and_warn(waiter, &Proc.new) if block_given? waiter.wait(params.merge(vpc_ids: [@id])) Vpc.new({ id: @id, client: @client }) end |