Class: Aws::EC2::Volume
- Inherits:
-
Object
- Object
- Aws::EC2::Volume
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-ec2/volume.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#attachments ⇒ Array<Types::VolumeAttachment>
<note markdown=“1”> This parameter is not returned by CreateVolume.
-
#availability_zone ⇒ String
The Availability Zone for the volume.
-
#create_time ⇒ Time
The time stamp when volume creation was initiated.
-
#encrypted ⇒ Boolean
Indicates whether the volume is encrypted.
-
#fast_restored ⇒ Boolean
<note markdown=“1”> This parameter is not returned by CreateVolume.
- #id ⇒ String (also: #volume_id)
-
#iops ⇒ Integer
The number of I/O operations per second (IOPS).
-
#kms_key_id ⇒ String
The Amazon Resource Name (ARN) of the KMS key that was used to protect the volume encryption key for the volume.
-
#multi_attach_enabled ⇒ Boolean
Indicates whether Amazon EBS Multi-Attach is enabled.
-
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
-
#size ⇒ Integer
The size of the volume, in GiBs.
-
#snapshot_id ⇒ String
The snapshot from which the volume was created, if applicable.
-
#sse_type ⇒ String
<note markdown=“1”> This parameter is not returned by CreateVolume.
-
#state ⇒ String
The volume state.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the volume.
-
#throughput ⇒ Integer
The throughput that the volume supports, in MiB/s.
-
#volume_type ⇒ String
The volume type.
Actions collapse
- #attach_to_instance(options = {}) ⇒ Types::VolumeAttachment
- #create_snapshot(options = {}) ⇒ Snapshot
- #create_tags(options = {}) ⇒ Tag::Collection
- #delete(options = {}) ⇒ EmptyStructure
- #delete_tags(options = {}) ⇒ Tag::Collection
- #describe_attribute(options = {}) ⇒ Types::DescribeVolumeAttributeResult
- #describe_status(options = {}) ⇒ Types::DescribeVolumeStatusResult
- #detach_from_instance(options = {}) ⇒ Types::VolumeAttachment
- #enable_io(options = {}) ⇒ EmptyStructure
- #modify_attribute(options = {}) ⇒ EmptyStructure
Associations collapse
- #identifiers ⇒ Object deprecated private Deprecated.
- #snapshots(options = {}) ⇒ Snapshot::Collection
Instance Method Summary collapse
- #client ⇒ Client
-
#data ⇒ Types::Volume
Returns the data for this Volume.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#initialize(*args) ⇒ Volume
constructor
A new instance of Volume.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
Constructor Details
#initialize(id, options = {}) ⇒ Volume #initialize(options = {}) ⇒ Volume
Returns a new instance of Volume.
22 23 24 25 26 27 28 |
# File 'lib/aws-sdk-ec2/volume.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
#attach_to_instance(options = {}) ⇒ Types::VolumeAttachment
307 308 309 310 311 312 313 |
# File 'lib/aws-sdk-ec2/volume.rb', line 307 def attach_to_instance( = {}) = .merge(volume_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.attach_volume() end resp.data end |
#attachments ⇒ Array<Types::VolumeAttachment>
<note markdown=“1”> This parameter is not returned by CreateVolume.
</note>
Information about the volume attachments.
44 45 46 |
# File 'lib/aws-sdk-ec2/volume.rb', line 44 def data[:attachments] end |
#availability_zone ⇒ String
The Availability Zone for the volume.
50 51 52 |
# File 'lib/aws-sdk-ec2/volume.rb', line 50 def availability_zone data[:availability_zone] end |
#create_snapshot(options = {}) ⇒ Snapshot
365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/aws-sdk-ec2/volume.rb', line 365 def create_snapshot( = {}) = .merge(volume_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.create_snapshot() end Snapshot.new( id: resp.data.snapshot_id, data: resp.data, client: @client ) end |
#create_tags(options = {}) ⇒ Tag::Collection
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/aws-sdk-ec2/volume.rb', line 399 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 |
#create_time ⇒ Time
The time stamp when volume creation was initiated.
56 57 58 |
# File 'lib/aws-sdk-ec2/volume.rb', line 56 def create_time data[:create_time] end |
#data ⇒ Types::Volume
Returns the data for this Aws::EC2::Volume. Calls Client#describe_volumes if #data_loaded? is ‘false`.
176 177 178 179 |
# File 'lib/aws-sdk-ec2/volume.rb', line 176 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
184 185 186 |
# File 'lib/aws-sdk-ec2/volume.rb', line 184 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
475 476 477 478 479 480 481 |
# File 'lib/aws-sdk-ec2/volume.rb', line 475 def delete( = {}) = .merge(volume_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_volume() end resp.data end |
#delete_tags(options = {}) ⇒ Tag::Collection
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/aws-sdk-ec2/volume.rb', line 446 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::DescribeVolumeAttributeResult
498 499 500 501 502 503 504 |
# File 'lib/aws-sdk-ec2/volume.rb', line 498 def describe_attribute( = {}) = .merge(volume_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_volume_attribute() end resp.data end |
#describe_status(options = {}) ⇒ Types::DescribeVolumeStatusResult
571 572 573 574 575 576 577 |
# File 'lib/aws-sdk-ec2/volume.rb', line 571 def describe_status( = {}) = Aws::Util.deep_merge(, volume_ids: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_volume_status() end resp.data end |
#detach_from_instance(options = {}) ⇒ Types::VolumeAttachment
608 609 610 611 612 613 614 |
# File 'lib/aws-sdk-ec2/volume.rb', line 608 def detach_from_instance( = {}) = .merge(volume_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.detach_volume() end resp.data end |
#enable_io(options = {}) ⇒ EmptyStructure
628 629 630 631 632 633 634 |
# File 'lib/aws-sdk-ec2/volume.rb', line 628 def enable_io( = {}) = .merge(volume_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.enable_volume_io() end resp.data end |
#encrypted ⇒ Boolean
Indicates whether the volume is encrypted.
62 63 64 |
# File 'lib/aws-sdk-ec2/volume.rb', line 62 def encrypted data[:encrypted] end |
#fast_restored ⇒ Boolean
<note markdown=“1”> This parameter is not returned by CreateVolume.
</note>
Indicates whether the volume was created using fast snapshot restore.
125 126 127 |
# File 'lib/aws-sdk-ec2/volume.rb', line 125 def fast_restored data[:fast_restored] end |
#id ⇒ String Also known as: volume_id
33 34 35 |
# File 'lib/aws-sdk-ec2/volume.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.
765 766 767 |
# File 'lib/aws-sdk-ec2/volume.rb', line 765 def identifiers { id: @id } end |
#iops ⇒ Integer
The number of I/O operations per second (IOPS). For ‘gp3`, `io1`, and `io2` volumes, this represents the number of IOPS that are provisioned for the volume. For `gp2` volumes, this represents the baseline performance of the volume and the rate at which the volume accumulates I/O credits for bursting.
103 104 105 |
# File 'lib/aws-sdk-ec2/volume.rb', line 103 def iops data[:iops] end |
#kms_key_id ⇒ String
The Amazon Resource Name (ARN) of the KMS key that was used to protect the volume encryption key for the volume.
69 70 71 |
# File 'lib/aws-sdk-ec2/volume.rb', line 69 def kms_key_id data[:kms_key_id] end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::EC2::Volume. Returns ‘self` making it possible to chain methods.
volume.reload.data
164 165 166 167 168 169 170 |
# File 'lib/aws-sdk-ec2/volume.rb', line 164 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_volumes(volume_ids: [@id]) end @data = resp.volumes[0] self end |
#modify_attribute(options = {}) ⇒ EmptyStructure
654 655 656 657 658 659 660 |
# File 'lib/aws-sdk-ec2/volume.rb', line 654 def modify_attribute( = {}) = .merge(volume_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.modify_volume_attribute() end resp.data end |
#multi_attach_enabled ⇒ Boolean
Indicates whether Amazon EBS Multi-Attach is enabled.
131 132 133 |
# File 'lib/aws-sdk-ec2/volume.rb', line 131 def multi_attach_enabled data[:multi_attach_enabled] end |
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
75 76 77 |
# File 'lib/aws-sdk-ec2/volume.rb', line 75 def outpost_arn data[:outpost_arn] end |
#size ⇒ Integer
The size of the volume, in GiBs.
81 82 83 |
# File 'lib/aws-sdk-ec2/volume.rb', line 81 def size data[:size] end |
#snapshot_id ⇒ String
The snapshot from which the volume was created, if applicable.
87 88 89 |
# File 'lib/aws-sdk-ec2/volume.rb', line 87 def snapshot_id data[:snapshot_id] end |
#snapshots(options = {}) ⇒ Snapshot::Collection
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'lib/aws-sdk-ec2/volume.rb', line 739 def snapshots( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "volume-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_snapshots() end resp.each_page do |page| batch = [] page.data.snapshots.each do |s| batch << Snapshot.new( id: s.snapshot_id, data: s, client: @client ) end y.yield(batch) end end Snapshot::Collection.new(batches) end |
#sse_type ⇒ String
<note markdown=“1”> This parameter is not returned by CreateVolume.
</note>
Reserved for future use.
147 148 149 |
# File 'lib/aws-sdk-ec2/volume.rb', line 147 def sse_type data[:sse_type] end |
#state ⇒ String
The volume state.
93 94 95 |
# File 'lib/aws-sdk-ec2/volume.rb', line 93 def state data[:state] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the volume.
109 110 111 |
# File 'lib/aws-sdk-ec2/volume.rb', line 109 def data[:tags] end |
#throughput ⇒ Integer
The throughput that the volume supports, in MiB/s.
137 138 139 |
# File 'lib/aws-sdk-ec2/volume.rb', line 137 def throughput data[:throughput] end |
#volume_type ⇒ String
The volume type.
115 116 117 |
# File 'lib/aws-sdk-ec2/volume.rb', line 115 def volume_type data[:volume_type] 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
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/aws-sdk-ec2/volume.rb', line 268 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 |