Class: HCloud::StorageBoxSnapshot

Inherits:
Resource
  • Object
show all
Defined in:
lib/hcloud/resources/storage_box_snapshot.rb

Overview

Represents a storage box’s snapshot

List all snapshots

storage_box = HCloud::StorageBox.find(1)
storage_box.snapshots
# => [#<HCloud::StorageBox::Snapshot id: 1, ...>, ...]

Search snapshots

storage_box = HCloud::StorageBox.find(1)
storage_box.snapshots.where(name: "monthly_backup")
# => #<HCloud::StorageBox::Snapshot id: 1, ...>

storage_box = HCloud::StorageBox.find(1)
storage_box.snapshots.where(label_selector: "environment=production")
# => #<HCloud::StorageBox::Snapshot id: 1, ...>

Find snapshot by ID

storage_box = HCloud::StorageBox.find(1)
storage_box.snapshots.find(1)
# => #<HCloud::StorageBox::Snapshot id: 1, ...>

Create snapshot

storage_box = HCloud::StorageBox.find(1)
snapshot = storage_box.snapshots.new(description: "my_snapshot")
snapshot.create
snapshot.created?
# => false

Note: this method returns a {HCloud::Action} instance rather than the created resource itself, as the snapshot is created asynchronously.
Reload the snapshot to check if it was created successfully.

snapshot.reload
snapshot.created?
# => true

snapshot = storage_box.snapshots.create(description: "my_snapshot")
# => #<HCloud::Action id: 1, ...>

Note: this method returns a {HCloud::Action} instance rather than the created resource itself

snapshot = HCloud::StorageBox::Snapshot.create(storage_box: 1, description: "my_snapshot")
# => #<HCloud::Action id: 1, ...>

Note: this method returns a {HCloud::Action} instance rather than the created resource itself

Update snapshot

storage_box = HCloud::StorageBox.find(1)
snapshot = storage_box.snapshots.find(1)
snapshot.description = "another_snapshot"
snapshot.update

Delete snapshot

storage_box = HCloud::StorageBox.find(1)
snapshot = storage_box.snapshots.find(1)
snapshot.delete
# => #<HCloud::Action id: 1, ...>

snapshot.deleted?
# => true

Note: this method returns a {HCloud::Action} instance rather than the deleted resource itself

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #initialize, #inspect, #to_h

Constructor Details

This class inherits a constructor from HCloud::Resource

Class Method Details

.clientObject



104
105
106
# File 'lib/hcloud/resources/storage_box_snapshot.rb', line 104

def self.client
  HCloud::Client.connection.storage_box_client
end

.resource_nameObject



100
101
102
# File 'lib/hcloud/resources/storage_box_snapshot.rb', line 100

def self.resource_name
  "snapshot"
end

Instance Method Details

#creatable_attributesObject



92
93
94
# File 'lib/hcloud/resources/storage_box_snapshot.rb', line 92

def creatable_attributes
  [:description]
end

#updatable_attributesObject



96
97
98
# File 'lib/hcloud/resources/storage_box_snapshot.rb', line 96

def updatable_attributes
  [:description, :labels]
end