Class: Aws::EC2::Snapshot
- Inherits:
-
Object
- Object
- Aws::EC2::Snapshot
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-ec2/snapshot.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#availability_zone ⇒ String
The Availability Zone or Local Zone of the snapshot.
-
#completion_duration_minutes ⇒ Integer
<note markdown=“1”> Only for snapshot copies created with time-based snapshot copy operations.
-
#completion_time ⇒ Time
The time stamp when the snapshot was completed.
-
#data_encryption_key_id ⇒ String
The data encryption key identifier for the snapshot.
-
#description ⇒ String
The description for the snapshot.
-
#encrypted ⇒ Boolean
Indicates whether the snapshot is encrypted.
- #id ⇒ String (also: #snapshot_id)
-
#kms_key_id ⇒ String
The Amazon Resource Name (ARN) of the KMS key that was used to protect the volume encryption key for the parent volume.
-
#outpost_arn ⇒ String
The ARN of the Outpost on which the snapshot is stored.
-
#owner_alias ⇒ String
The Amazon Web Services owner alias, from an Amazon-maintained list (‘amazon`).
-
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the EBS snapshot.
-
#progress ⇒ String
The progress of the snapshot, as a percentage.
-
#restore_expiry_time ⇒ Time
Only for archived snapshots that are temporarily restored.
-
#sse_type ⇒ String
Reserved for future use.
-
#start_time ⇒ Time
The time stamp when the snapshot was initiated.
-
#state ⇒ String
The snapshot state.
-
#state_message ⇒ String
Encrypted Amazon EBS snapshots are copied asynchronously.
-
#storage_tier ⇒ String
The storage tier in which the snapshot is stored.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the snapshot.
-
#transfer_type ⇒ String
<note markdown=“1”> Only for snapshot copies.
-
#volume_id ⇒ String
The ID of the volume that was used to create the snapshot.
-
#volume_size ⇒ Integer
The size of the volume, in GiB.
Actions collapse
- #copy(options = {}) ⇒ Types::CopySnapshotResult
- #create_tags(options = {}) ⇒ Tag::Collection
- #delete(options = {}) ⇒ EmptyStructure
- #delete_tags(options = {}) ⇒ Tag::Collection
- #describe_attribute(options = {}) ⇒ Types::DescribeSnapshotAttributeResult
- #modify_attribute(options = {}) ⇒ EmptyStructure
- #reset_attribute(options = {}) ⇒ EmptyStructure
Associations collapse
- #identifiers ⇒ Object deprecated private Deprecated.
- #volume ⇒ Volume?
Instance Method Summary collapse
- #client ⇒ Client
-
#data ⇒ Types::Snapshot
Returns the data for this Snapshot.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#initialize(*args) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
- #wait_until_completed(options = {}, &block) ⇒ Snapshot
Constructor Details
#initialize(id, options = {}) ⇒ Snapshot #initialize(options = {}) ⇒ Snapshot
Returns a new instance of Snapshot.
22 23 24 25 26 27 28 |
# File 'lib/aws-sdk-ec2/snapshot.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
#availability_zone ⇒ String
The Availability Zone or Local Zone of the snapshot. For example, ‘us-west-1a` (Availability Zone) or `us-west-2-lax-1a` (Local Zone).
90 91 92 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 90 def availability_zone data[:availability_zone] end |
#completion_duration_minutes ⇒ Integer
<note markdown=“1”> Only for snapshot copies created with time-based snapshot copy operations.
</note>
The completion duration requested for the time-based snapshot copy operation.
122 123 124 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 122 def completion_duration_minutes data[:completion_duration_minutes] end |
#completion_time ⇒ Time
The time stamp when the snapshot was completed.
128 129 130 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 128 def completion_time data[:completion_time] end |
#copy(options = {}) ⇒ Types::CopySnapshotResult
493 494 495 496 497 498 499 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 493 def copy( = {}) = .merge(source_snapshot_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.copy_snapshot() end resp.data end |
#create_tags(options = {}) ⇒ Tag::Collection
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 523 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::Snapshot
Returns the data for this Aws::EC2::Snapshot. Calls Client#describe_snapshots if #data_loaded? is ‘false`.
236 237 238 239 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 236 def data load unless @data @data end |
#data_encryption_key_id ⇒ String
The data encryption key identifier for the snapshot. This value is a unique identifier that corresponds to the data encryption key that was used to encrypt the original volume or snapshot copy. Because data encryption keys are inherited by volumes created from snapshots, and vice versa, if snapshots share the same data encryption key identifier, then they belong to the same volume/snapshot lineage. This parameter is only returned by DescribeSnapshots.
207 208 209 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 207 def data_encryption_key_id data[:data_encryption_key_id] end |
#data_loaded? ⇒ Boolean
244 245 246 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 244 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
599 600 601 602 603 604 605 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 599 def delete( = {}) = .merge(snapshot_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_snapshot() end resp.data end |
#delete_tags(options = {}) ⇒ Tag::Collection
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 570 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::DescribeSnapshotAttributeResult
622 623 624 625 626 627 628 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 622 def describe_attribute( = {}) = .merge(snapshot_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_snapshot_attribute() end resp.data end |
#description ⇒ String
The description for the snapshot.
176 177 178 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 176 def description data[:description] end |
#encrypted ⇒ Boolean
Indicates whether the snapshot is encrypted.
188 189 190 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 188 def encrypted data[:encrypted] end |
#id ⇒ String Also known as: snapshot_id
33 34 35 |
# File 'lib/aws-sdk-ec2/snapshot.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.
719 720 721 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 719 def identifiers { id: @id } 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 parent volume.
195 196 197 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 195 def kms_key_id data[:kms_key_id] end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::EC2::Snapshot. Returns ‘self` making it possible to chain methods.
snapshot.reload.data
224 225 226 227 228 229 230 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 224 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_snapshots(snapshot_ids: [@id]) end @data = resp.snapshots[0] self end |
#modify_attribute(options = {}) ⇒ EmptyStructure
671 672 673 674 675 676 677 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 671 def modify_attribute( = {}) = .merge(snapshot_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.modify_snapshot_attribute() end resp.data end |
#outpost_arn ⇒ String
The ARN of the Outpost on which the snapshot is stored. For more information, see [Amazon EBS local snapshots on Outposts] in the *Amazon EBS User Guide*.
[1]: docs.aws.amazon.com/ebs/latest/userguide/snapshots-outposts.html
54 55 56 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 54 def outpost_arn data[:outpost_arn] end |
#owner_alias ⇒ String
The Amazon Web Services owner alias, from an Amazon-maintained list (‘amazon`). This is not the user-configured Amazon Web Services account alias set using the IAM console.
42 43 44 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 42 def owner_alias data[:owner_alias] end |
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the EBS snapshot.
170 171 172 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 170 def owner_id data[:owner_id] end |
#progress ⇒ String
The progress of the snapshot, as a percentage.
164 165 166 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 164 def progress data[:progress] end |
#reset_attribute(options = {}) ⇒ EmptyStructure
695 696 697 698 699 700 701 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 695 def reset_attribute( = {}) = .merge(snapshot_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.reset_snapshot_attribute() end resp.data end |
#restore_expiry_time ⇒ Time
Only for archived snapshots that are temporarily restored. Indicates the date and time when a temporarily restored snapshot will be automatically re-archived.
77 78 79 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 77 def restore_expiry_time data[:restore_expiry_time] end |
#sse_type ⇒ String
Reserved for future use.
83 84 85 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 83 def sse_type data[:sse_type] end |
#start_time ⇒ Time
The time stamp when the snapshot was initiated.
158 159 160 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 158 def start_time data[:start_time] end |
#state ⇒ String
The snapshot state.
142 143 144 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 142 def state data[:state] end |
#state_message ⇒ String
Encrypted Amazon EBS snapshots are copied asynchronously. If a snapshot copy operation fails (for example, if the proper KMS permissions are not obtained) this field displays error state details to help you diagnose why the error occurred. This parameter is only returned by DescribeSnapshots.
152 153 154 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 152 def data[:state_message] end |
#storage_tier ⇒ String
The storage tier in which the snapshot is stored. ‘standard` indicates that the snapshot is stored in the standard snapshot storage tier and that it is ready for use. `archive` indicates that the snapshot is currently archived and that it must be restored before it can be used.
69 70 71 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 69 def storage_tier data[:storage_tier] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the snapshot.
60 61 62 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 60 def data[:tags] end |
#transfer_type ⇒ String
<note markdown=“1”> Only for snapshot copies.
</note>
Indicates whether the snapshot copy was created with a standard or time-based snapshot copy operation. Time-based snapshot copy operations complete within the completion duration specified in the request. Standard snapshot copy operations are completed on a best-effort basis.
-
‘standard` - The snapshot copy was created with a standard snapshot copy operation.
-
‘time-based` - The snapshot copy was created with a time-based snapshot copy operation.
110 111 112 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 110 def transfer_type data[:transfer_type] end |
#volume ⇒ Volume?
706 707 708 709 710 711 712 713 714 715 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 706 def volume if data[:volume_id] Volume.new( id: data[:volume_id], client: @client ) else nil end end |
#volume_id ⇒ String
The ID of the volume that was used to create the snapshot. Snapshots created by the CopySnapshot action have an arbitrary volume ID that should not be used for any purpose.
136 137 138 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 136 def volume_id data[:volume_id] end |
#volume_size ⇒ Integer
The size of the volume, in GiB.
182 183 184 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 182 def volume_size data[:volume_size] 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
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 348 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_completed(options = {}, &block) ⇒ Snapshot
254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/aws-sdk-ec2/snapshot.rb', line 254 def wait_until_completed( = {}, &block) , params = () waiter = Waiters::SnapshotCompleted.new() yield_waiter_and_warn(waiter, &block) if block_given? resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(snapshot_ids: [@id])) end Snapshot.new({ id: @id, data: resp.data.snapshots[0], client: @client }) end |