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
-
#block_public_access_states ⇒ Types::BlockPublicAccessStates
The state of VPC Block Public Access (BPA).
-
#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.
-
#encryption_control ⇒ Types::VpcEncryptionControl
Describes the configuration and state of VPC encryption controls.
- #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?
- #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 = {}) {|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 '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
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 986 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.metric('RESOURCE_MODEL') 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
317 318 319 320 321 322 323 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 317 def ( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end resp.data end |
#attach_classic_link_instance(options = {}) ⇒ Types::AttachClassicLinkVpcResult
344 345 346 347 348 349 350 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 344 def attach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.attach_classic_link_vpc() end resp.data end |
#attach_internet_gateway(options = {}) ⇒ EmptyStructure
367 368 369 370 371 372 373 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 367 def attach_internet_gateway( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.attach_internet_gateway() end resp.data end |
#block_public_access_states ⇒ Types::BlockPublicAccessStates
The state of VPC Block Public Access (BPA).
89 90 91 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 89 def block_public_access_states data[:block_public_access_states] end |
#cidr_block ⇒ String
The primary IPv4 CIDR block for the VPC.
101 102 103 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 101 def cidr_block data[:cidr_block] end |
#cidr_block_association_set ⇒ Array<Types::VpcCidrBlockAssociation>
Information about the IPv4 CIDR blocks associated with the VPC.
58 59 60 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 58 def cidr_block_association_set data[:cidr_block_association_set] end |
#create_network_acl(options = {}) ⇒ NetworkAcl
409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 409 def create_network_acl( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 455 def create_route_table( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
509 510 511 512 513 514 515 516 517 518 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 509 def create_security_group( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.create_security_group() end SecurityGroup.new( id: resp.data.group_id, client: @client ) end |
#create_subnet(options = {}) ⇒ Subnet
598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 598 def create_subnet( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 632 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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`.
136 137 138 139 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 136 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
144 145 146 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 144 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
708 709 710 711 712 713 714 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 708 def delete( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_vpc() end resp.data end |
#delete_tags(options = {}) ⇒ Tag::Collection
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 679 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
731 732 733 734 735 736 737 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 731 def describe_attribute( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_vpc_attribute() end resp.data end |
#detach_classic_link_instance(options = {}) ⇒ Types::DetachClassicLinkVpcResult
754 755 756 757 758 759 760 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 754 def detach_classic_link_instance( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.detach_classic_link_vpc() end resp.data end |
#detach_internet_gateway(options = {}) ⇒ EmptyStructure
777 778 779 780 781 782 783 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 777 def detach_internet_gateway( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.detach_internet_gateway() end resp.data end |
#dhcp_options ⇒ DhcpOptions?
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1011 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.
107 108 109 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 107 def data[:dhcp_options_id] end |
#disable_classic_link(options = {}) ⇒ Types::DisableVpcClassicLinkResult
797 798 799 800 801 802 803 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 797 def disable_classic_link( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.disable_vpc_classic_link() end resp.data end |
#enable_classic_link(options = {}) ⇒ Types::EnableVpcClassicLinkResult
817 818 819 820 821 822 823 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 817 def enable_classic_link( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.enable_vpc_classic_link() end resp.data end |
#encryption_control ⇒ Types::VpcEncryptionControl
Describes the configuration and state of VPC encryption controls.
For more information, see [Enforce VPC encryption in transit] in the *Amazon VPC User Guide*.
[1]: docs.aws.amazon.com/vpc/latest/userguide/vpc-encryption-controls.html
77 78 79 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 77 def encryption_control data[:encryption_control] end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the Vpc exists.
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 151 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 'lib/aws-sdk-ec2/vpc.rb', line 33 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.
2341 2342 2343 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 2341 def identifiers { id: @id } end |
#instance_tenancy ⇒ String
The allowed tenancy of instances launched into the VPC.
46 47 48 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 46 def instance_tenancy data[:instance_tenancy] end |
#instances(options = {}) ⇒ Instance::Collection
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1492 def instances( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1564 def internet_gateways( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "attachment.vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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.
52 53 54 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 52 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.
64 65 66 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 64 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
124 125 126 127 128 129 130 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 124 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_vpcs(vpc_ids: [@id]) end @data = resp.vpcs[0] self end |
#modify_attribute(options = {}) ⇒ EmptyStructure
861 862 863 864 865 866 867 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 861 def modify_attribute( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.modify_vpc_attribute() end resp.data end |
#network_acls(options = {}) ⇒ NetworkAcl::Collection
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1666 def network_acls( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1838 def network_interfaces( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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.
40 41 42 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 40 def owner_id data[:owner_id] end |
#request_vpc_peering_connection(options = {}) ⇒ VpcPeeringConnection
909 910 911 912 913 914 915 916 917 918 919 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 909 def request_vpc_peering_connection( = {}) = .merge(vpc_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 1925 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.metric('RESOURCE_MODEL') 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
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 2043 def route_tables( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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
2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 2179 def security_groups( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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.
95 96 97 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 95 def state data[:state] end |
#subnets(options = {}) ⇒ Subnet::Collection
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 2315 def subnets( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "vpc-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') 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.
83 84 85 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 83 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
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 280 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.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |
#wait_until_available(options = {}, &block) ⇒ Vpc
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 168 def wait_until_available( = {}, &block) , params = () waiter = Waiters::VpcAvailable.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(vpc_ids: [@id])) end Vpc.new({ id: @id, client: @client }) end |
#wait_until_exists(options = {}, &block) ⇒ Vpc
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/aws-sdk-ec2/vpc.rb', line 187 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::VpcExists.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(vpc_ids: [@id])) end Vpc.new({ id: @id, client: @client }) end |