Class: Aws::EC2::Volume
- Inherits:
-
Object
- Object
- Aws::EC2::Volume
- Defined in:
- gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#attachments ⇒ Array<Types::VolumeAttachment>
This parameter is not returned by CreateVolume. -
#availability_zone ⇒ String
The Availability Zone for the volume.
-
#availability_zone_id ⇒ String
The ID of 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
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.
-
#multi_availability_zone_configuration ⇒ Types::MultiAvailabilityZoneVolumeConfiguration
The Multi-Availability Zone configuration of the volume.
-
#operator ⇒ Types::OperatorResponse
The service provider that manages the volume.
-
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
-
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the volume.
-
#size ⇒ Integer
The size of the volume, in GiBs.
-
#snapshot_id ⇒ String
The snapshot from which the volume was created, if applicable.
-
#source_volume_id ⇒ String
The ID of the source volume from which the volume copy was created.
-
#sse_type ⇒ String
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.
-
#trim_on_attach ⇒ String
Specifies whether the volume reports TRIM support to the operating system when the volume is attached to an EC2 instance.
-
#volume_arn ⇒ String
The Amazon Resource Name (ARN) of the volume.
-
#volume_initialization_rate ⇒ Integer
The Amazon EBS Provisioned Rate for Volume Initialization (volume initialization rate) specified for the volume during creation, 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
Instance Method Summary collapse
-
#client ⇒ Client
-
#data ⇒ Types::Volume
Returns the data for this Volume.
-
#data_loaded? ⇒ Boolean
Returns
trueif 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 'gems/aws-sdk-ec2/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
383 384 385 386 387 388 389 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 383 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>
Information about the volume attachments.
206 207 208 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 206 def data[:attachments] end |
#availability_zone ⇒ String
The Availability Zone for the volume.
184 185 186 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 184 def availability_zone data[:availability_zone] end |
#availability_zone_id ⇒ String
The ID of the Availability Zone for the volume.
40 41 42 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 40 def availability_zone_id data[:availability_zone_id] end |
#client ⇒ Client
226 227 228 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 226 def client @client end |
#create_snapshot(options = {}) ⇒ Snapshot
453 454 455 456 457 458 459 460 461 462 463 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 453 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
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 487 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.
196 197 198 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 196 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.
248 249 250 251 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 248 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
256 257 258 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 256 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
563 564 565 566 567 568 569 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 563 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
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 534 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
586 587 588 589 590 591 592 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 586 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
671 672 673 674 675 676 677 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 671 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
708 709 710 711 712 713 714 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 708 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
728 729 730 731 732 733 734 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 728 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.
212 213 214 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 212 def encrypted data[:encrypted] end |
#fast_restored ⇒ Boolean
Indicates whether the volume was created using fast snapshot restore.
85 86 87 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 85 def fast_restored data[:fast_restored] end |
#id ⇒ String Also known as: volume_id
33 34 35 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 33 def id @id end |
#iops ⇒ Integer
The number of I/O operations per second (IOPS). For gp3, gp3a,
io1, io2, and io2a 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.
63 64 65 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 63 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.
219 220 221 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 219 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
236 237 238 239 240 241 242 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 236 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
754 755 756 757 758 759 760 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 754 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.
91 92 93 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 91 def multi_attach_enabled data[:multi_attach_enabled] end |
#multi_availability_zone_configuration ⇒ Types::MultiAvailabilityZoneVolumeConfiguration
The Multi-Availability Zone configuration of the volume. Returned only for Multi-Availability Zone volumes.
141 142 143 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 141 def multi_availability_zone_configuration data[:multi_availability_zone_configuration] end |
#operator ⇒ Types::OperatorResponse
The service provider that manages the volume.
113 114 115 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 113 def operator data[:operator] end |
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
46 47 48 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 46 def outpost_arn data[:outpost_arn] end |
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the volume.
134 135 136 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 134 def owner_id data[:owner_id] end |
#size ⇒ Integer
The size of the volume, in GiBs.
172 173 174 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 172 def size data[:size] end |
#snapshot_id ⇒ String
The snapshot from which the volume was created, if applicable.
178 179 180 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 178 def snapshot_id data[:snapshot_id] end |
#snapshots(options = {}) ⇒ Snapshot::Collection
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 842 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 |
#source_volume_id ⇒ String
The ID of the source volume from which the volume copy was created. Only for volume copies.
53 54 55 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 53 def source_volume_id data[:source_volume_id] end |
#sse_type ⇒ String
Reserved for future use.
107 108 109 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 107 def sse_type data[:sse_type] end |
#state ⇒ String
The volume state.
190 191 192 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 190 def state data[:state] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the volume.
69 70 71 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 69 def data[:tags] end |
#throughput ⇒ Integer
The throughput that the volume supports, in MiB/s.
97 98 99 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 97 def throughput data[:throughput] end |
#trim_on_attach ⇒ String
Specifies whether the volume reports TRIM support to the operating
system when the volume is attached to an EC2 instance. Amazon EBS
applies this intent only when the volume attaches to an EC2 instance,
and TRIM support on the volume stays the same for the life of the
attachment. To check whether an attached volume is reporting TRIM
support, use TrimState in the attachments of the volume. Volumes
created from a snapshot don't inherit the source volume's setting.
For more information, see Amazon EBS TRIM in the Amazon EBS User
Guide.
Valid values:
enabled: The volume reports TRIM support to the operating system.disabled: The volume does not report TRIM support to the operating system.
166 167 168 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 166 def trim_on_attach data[:trim_on_attach] end |
#volume_arn ⇒ String
The Amazon Resource Name (ARN) of the volume.
128 129 130 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 128 def volume_arn data[:volume_arn] end |
#volume_initialization_rate ⇒ Integer
The Amazon EBS Provisioned Rate for Volume Initialization (volume
initialization rate) specified for the volume during creation, in
MiB/s. If no volume initialization rate was specified, the value is
null.
122 123 124 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 122 def volume_initialization_rate data[:volume_initialization_rate] end |
#volume_type ⇒ String
The volume type.
75 76 77 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 75 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
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/volume.rb', line 340 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 |