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.
-
#owner_id ⇒ String
The ID of the AWS account that owns the 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
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 755 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
285 286 287 288 289 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 285 def ( = {}) = .merge(vpc_id: @id) resp = @client.() resp.data end |
#attach_classic_link_instance(options = {}) ⇒ Types::AttachClassicLinkVpcResult
311 312 313 314 315 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 311 def attach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = @client.attach_classic_link_vpc() resp.data end |
#attach_internet_gateway(options = {}) ⇒ EmptyStructure
332 333 334 335 336 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 332 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.
73 74 75 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 73 def cidr_block_association_set data[:cidr_block_association_set] end |
#create_network_acl(options = {}) ⇒ NetworkAcl
350 351 352 353 354 355 356 357 358 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 350 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
372 373 374 375 376 377 378 379 380 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 372 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
414 415 416 417 418 419 420 421 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 414 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
453 454 455 456 457 458 459 460 461 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 453 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
485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 485 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`.
112 113 114 115 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 112 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
120 121 122 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 120 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
512 513 514 515 516 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 512 def delete( = {}) = .merge(vpc_id: @id) resp = @client.delete_vpc() resp.data end |
#describe_attribute(options = {}) ⇒ Types::DescribeVpcAttributeResult
533 534 535 536 537 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 533 def describe_attribute( = {}) = .merge(vpc_id: @id) resp = @client.describe_vpc_attribute() resp.data end |
#detach_classic_link_instance(options = {}) ⇒ Types::DetachClassicLinkVpcResult
554 555 556 557 558 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 554 def detach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = @client.detach_classic_link_vpc() resp.data end |
#detach_internet_gateway(options = {}) ⇒ EmptyStructure
575 576 577 578 579 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 575 def detach_internet_gateway( = {}) = .merge(vpc_id: @id) resp = @client.detach_internet_gateway() resp.data end |
#dhcp_options ⇒ DhcpOptions?
776 777 778 779 780 781 782 783 784 785 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 776 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
593 594 595 596 597 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 593 def disable_classic_link( = {}) = .merge(vpc_id: @id) resp = @client.disable_vpc_classic_link() resp.data end |
#enable_classic_link(options = {}) ⇒ Types::EnableVpcClassicLinkResult
611 612 613 614 615 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 611 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.
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 127 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.
1841 1842 1843 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1841 def identifiers { id: @id } end |
#instance_tenancy ⇒ String
The allowed tenancy of instances launched into the VPC.
61 62 63 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 61 def instance_tenancy data[:instance_tenancy] end |
#instances(options = {}) ⇒ Instance::Collection
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1072 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
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1142 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.
67 68 69 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 67 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.
79 80 81 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 79 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
102 103 104 105 106 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 102 def load resp = @client.describe_vpcs(vpc_ids: [@id]) @data = resp.vpcs[0] self end |
#modify_attribute(options = {}) ⇒ EmptyStructure
647 648 649 650 651 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 647 def modify_attribute( = {}) = .merge(vpc_id: @id) resp = @client.modify_vpc_attribute() resp.data end |
#network_acls(options = {}) ⇒ NetworkAcl::Collection
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1238 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
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1393 def network_interfaces( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-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 VPC.
55 56 57 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 55 def owner_id data[:owner_id] end |
#request_vpc_peering_connection(options = {}) ⇒ VpcPeeringConnection
680 681 682 683 684 685 686 687 688 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 680 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
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1478 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
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1592 def route_tables( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = @client.describe_route_tables() resp.each_page do |page| batch = [] page.data.route_tables.each do |r| batch << RouteTable.new( id: r.route_table_id, data: r, client: @client ) end y.yield(batch) end end RouteTable::Collection.new(batches) end |
#security_groups(options = {}) ⇒ SecurityGroup::Collection
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1725 def security_groups( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = @client.describe_security_groups() resp.each_page do |page| batch = [] page.data.security_groups.each do |s| batch << SecurityGroup.new( id: s.group_id, data: s, client: @client ) end y.yield(batch) end 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
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1819 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.
85 86 87 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 85 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
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 250 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
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 144 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
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 161 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 |