Class: Aws::EC2::Vpc
- Inherits:
-
Object
- Object
- Aws::EC2::Vpc
- Defined in:
- gems/aws-sdk-ec2/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.
-
#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 Amazon Web Services 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
-
#delete_tags(options = {}) ⇒ Tag::Collection
-
#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?
-
#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 = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
-
#wait_until_available(options = {}, &block) ⇒ Vpc
-
#wait_until_exists(options = {}, &block) ⇒ Vpc
Constructor Details
#initialize(id, options = {}) ⇒ Vpc #initialize(options = {}) ⇒ Vpc
Returns a new instance of Vpc.
22 23 24 25 26 27 28 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.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
#accepted_vpc_peering_connections(options = {}) ⇒ VpcPeeringConnection::Collection
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 944 def accepted_vpc_peering_connections( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "accepter-vpc-info.vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_vpc_peering_connections() end resp.each_page do |page| batch = [] page.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 end VpcPeeringConnection::Collection.new(batches) end |
#associate_dhcp_options(options = {}) ⇒ EmptyStructure
298 299 300 301 302 303 304 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 298 def ( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.() end resp.data end |
#attach_classic_link_instance(options = {}) ⇒ Types::AttachClassicLinkVpcResult
326 327 328 329 330 331 332 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 326 def attach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.attach_classic_link_vpc() end resp.data end |
#attach_internet_gateway(options = {}) ⇒ EmptyStructure
349 350 351 352 353 354 355 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 349 def attach_internet_gateway( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.attach_internet_gateway() end resp.data end |
#cidr_block ⇒ String
The primary IPv4 CIDR block for the VPC.
40 41 42 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 40 def cidr_block data[:cidr_block] end |
#cidr_block_association_set ⇒ Array<Types::VpcCidrBlockAssociation>
Information about the IPv4 CIDR blocks associated with the VPC.
76 77 78 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 76 def cidr_block_association_set data[:cidr_block_association_set] end |
#client ⇒ Client
95 96 97 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 95 def client @client end |
#create_network_acl(options = {}) ⇒ NetworkAcl
382 383 384 385 386 387 388 389 390 391 392 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 382 def create_network_acl( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.create_network_acl() end NetworkAcl.new( id: resp.data.network_acl.network_acl_id, data: resp.data.network_acl, client: @client ) end |
#create_route_table(options = {}) ⇒ RouteTable
419 420 421 422 423 424 425 426 427 428 429 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 419 def create_route_table( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.create_route_table() end RouteTable.new( id: resp.data.route_table.route_table_id, data: resp.data.route_table, client: @client ) end |
#create_security_group(options = {}) ⇒ SecurityGroup
476 477 478 479 480 481 482 483 484 485 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 476 def create_security_group( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.create_security_group() end SecurityGroup.new( id: resp.data.group_id, client: @client ) end |
#create_subnet(options = {}) ⇒ Subnet
556 557 558 559 560 561 562 563 564 565 566 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 556 def create_subnet( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.create_subnet() end Subnet.new( id: resp.data.subnet.subnet_id, data: resp.data.subnet, client: @client ) end |
#create_tags(options = {}) ⇒ Tag::Collection
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 590 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 |
#data ⇒ Types::Vpc
Returns the data for this Aws::EC2::Vpc. Calls
Client#describe_vpcs if #data_loaded? is false
.
117 118 119 120 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 117 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
125 126 127 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 125 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
666 667 668 669 670 671 672 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 666 def delete( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.delete_vpc() end resp.data end |
#delete_tags(options = {}) ⇒ Tag::Collection
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 637 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 |
#describe_attribute(options = {}) ⇒ Types::DescribeVpcAttributeResult
689 690 691 692 693 694 695 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 689 def describe_attribute( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_vpc_attribute() end resp.data end |
#detach_classic_link_instance(options = {}) ⇒ Types::DetachClassicLinkVpcResult
712 713 714 715 716 717 718 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 712 def detach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.detach_classic_link_vpc() end resp.data end |
#detach_internet_gateway(options = {}) ⇒ EmptyStructure
735 736 737 738 739 740 741 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 735 def detach_internet_gateway( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.detach_internet_gateway() end resp.data end |
#dhcp_options ⇒ DhcpOptions?
969 970 971 972 973 974 975 976 977 978 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 969 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.
46 47 48 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 46 def data[:dhcp_options_id] end |
#disable_classic_link(options = {}) ⇒ Types::DisableVpcClassicLinkResult
755 756 757 758 759 760 761 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 755 def disable_classic_link( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.disable_vpc_classic_link() end resp.data end |
#enable_classic_link(options = {}) ⇒ Types::EnableVpcClassicLinkResult
775 776 777 778 779 780 781 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 775 def enable_classic_link( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.enable_vpc_classic_link() end resp.data end |
#exists?(options = {}) ⇒ Boolean
Returns true
if the Vpc exists.
132 133 134 135 136 137 138 139 140 141 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 132 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
33 34 35 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 33 def id @id end |
#instance_tenancy ⇒ String
The allowed tenancy of instances launched into the VPC.
64 65 66 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 64 def instance_tenancy data[:instance_tenancy] end |
#instances(options = {}) ⇒ Instance::Collection
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 1283 def instances( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-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 |
#internet_gateways(options = {}) ⇒ InternetGateway::Collection
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 1355 def internet_gateways( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "attachment.vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_internet_gateways() end resp.each_page do |page| batch = [] page.data.internet_gateways.each do |i| batch << InternetGateway.new( id: i.internet_gateway_id, data: i, client: @client ) end y.yield(batch) end 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.
70 71 72 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 70 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.
82 83 84 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 82 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
105 106 107 108 109 110 111 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 105 def load resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_vpcs(vpc_ids: [@id]) end @data = resp.vpcs[0] self end |
#modify_attribute(options = {}) ⇒ EmptyStructure
819 820 821 822 823 824 825 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 819 def modify_attribute( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.modify_vpc_attribute() end resp.data end |
#network_acls(options = {}) ⇒ NetworkAcl::Collection
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 1459 def network_acls( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_network_acls() end resp.each_page do |page| batch = [] page.data.network_acls.each do |n| batch << NetworkAcl.new( id: n.network_acl_id, data: n, client: @client ) end y.yield(batch) end end NetworkAcl::Collection.new(batches) end |
#network_interfaces(options = {}) ⇒ NetworkInterface::Collection
1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 1623 def network_interfaces( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-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 |
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the VPC.
58 59 60 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 58 def owner_id data[:owner_id] end |
#request_vpc_peering_connection(options = {}) ⇒ VpcPeeringConnection
867 868 869 870 871 872 873 874 875 876 877 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 867 def request_vpc_peering_connection( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.feature('resource') do @client.create_vpc_peering_connection() end 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
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 1710 def requested_vpc_peering_connections( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "requester-vpc-info.vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_vpc_peering_connections() end resp.each_page do |page| batch = [] page.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 end VpcPeeringConnection::Collection.new(batches) end |
#route_tables(options = {}) ⇒ RouteTable::Collection
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 1827 def route_tables( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_route_tables() end 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
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 1965 def security_groups( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_security_groups() end 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.
52 53 54 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 52 def state data[:state] end |
#subnets(options = {}) ⇒ Subnet::Collection
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 2101 def subnets( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.feature('resource') do @client.describe_subnets() end resp.each_page do |page| batch = [] page.data.subnets.each do |s| batch << Subnet.new( id: s.subnet_id, data: s, client: @client ) end y.yield(batch) end end Subnet::Collection.new(batches) end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the VPC.
88 89 90 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 88 def data[:tags] 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
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 261 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 |
#wait_until_available(options = {}, &block) ⇒ Vpc
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 149 def wait_until_available( = {}, &block) , params = () waiter = Waiters::VpcAvailable.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.feature('resource') do waiter.wait(params.merge(vpc_ids: [@id])) end Vpc.new({ id: @id, client: @client }) end |
#wait_until_exists(options = {}, &block) ⇒ Vpc
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc.rb', line 168 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::VpcExists.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.feature('resource') do waiter.wait(params.merge(vpc_ids: [@id])) end Vpc.new({ id: @id, client: @client }) end |