Class: Profitbricks::Snapshot

Inherits:
Model
  • Object
show all
Defined in:
lib/profitbricks/snapshot.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#attributes, belongs_to, has_many, #reload

Constructor Details

#initialize(hash, parent = nil) ⇒ Snapshot

Returns a new instance of Snapshot.



4
5
6
# File 'lib/profitbricks/snapshot.rb', line 4

def initialize(hash, parent=nil)
  super(hash)
end

Class Method Details

.allArray <Snapshot>

Provides a list of all snapshots available to this account

Returns:

  • (Array <Snapshot>)

    Array of all available Snapshots



51
52
53
54
55
56
# File 'lib/profitbricks/snapshot.rb', line 51

def all
  resp = Profitbricks.request :get_all_snapshots
  [resp].flatten.compact.collect do |snapshot|
    PB::Snapshot.new(snapshot)
  end
end

.create(options = {}) ⇒ Boolean

Creates a snapshot of an existing storage device.

The size of the snapshot will be the same as the size of the storage it was taken from independent of how much of it is in use. Any snapshot will be charged to your account and billed like an HD storage of the same size.

Parameters:

  • options (Hash) (defaults to: {})

    parameters for the new NIC

Options Hash (options):

  • :storage_id (String)

    Identifier of the virtual storage for which a snapshot shall be created (required)

  • :name (String)

    Name of the snapshot to be created

  • :description (String)

    Additional field to provide customized information about the data in this snapshot

Returns:

  • (Boolean)

    true on success



67
68
69
70
71
# File 'lib/profitbricks/snapshot.rb', line 67

def create(options = {})
  options[:snapshot_name] = options.delete :name if options[:name]
  response = Profitbricks.request :create_snapshot, options
  true
end

.find(options = {}) ⇒ Snapshot

Returns information about a particular Snapshot

Parameters:

  • options (Hash) (defaults to: {})

    currently just :id is supported

Options Hash (options):

  • :id (String)

    The id of the Snapshot to locate

  • :name (String)

    The name of the Snapshot

Returns:



79
80
81
82
83
84
85
86
# File 'lib/profitbricks/snapshot.rb', line 79

def find(options = {})
  if options[:name]
    return PB::Snapshot.all().select { |s| s.name == options[:name] }.first
  end
  raise "Unable to locate the Snapshot named '#{options[:name]}'" unless options[:id]
  response = Profitbricks.request :get_snapshot, snapshot_id: options[:id]
  PB::Snapshot.new(response)
end

Instance Method Details

#deleteBoolean

Deletes a snapshot. Please be aware that deleted snapshots and related data in this snapshot cannot be recovered anymore.

Returns:

  • (Boolean)

    true on success, false otherwise



30
31
32
33
# File 'lib/profitbricks/snapshot.rb', line 30

def delete
  response = Profitbricks.request :delete_snapshot, snapshot_id: self.id
  return true
end

#rollback(options = {}) ⇒ Boolean

Using the rollback option you may redeploy the snapshotted state on a storage.

Attention: The current state of the storage will be lost unless you create another snapshot before rolling back.

Parameters:

  • options (Hash) (defaults to: {})

    parameters

Options Hash (options):

  • :storage_id (String)

    Identifier of the virtual storage as target for the snapshot

Returns:

  • (Boolean)

    true on success, false otherwise



42
43
44
45
# File 'lib/profitbricks/snapshot.rb', line 42

def rollback(options = {})
  response = Profitbricks.request :rollback_snapshot, options.merge(:snapshot_id => self.id)
  return true
end

#update(options = {}) ⇒ Boolean

Updates meta data of a snapshot. This meta data can be relevant as they trigger other features like Live Vertical Scaling of CPU or RAM.

Parameters:

  • options (Hash) (defaults to: {})

    parameters to update

Options Hash (options):

  • :description (String)

    Text field to add additional information (e.g. for details about time or reason why snapshot was created)

  • :name (Fixnum)

    name of snapshot

  • :bootable (Boolean)

    flag of type boolean

  • :os_type (String)

    flag to specify OS type; relevant for license accounting in case snapshot gets redeployed on further virtual storage instances

  • :cpu_hot_plug (Boolean)

    snapshot contains capabilities to hotplug CPU; flag of type boolean

  • :ram_hot_plug (Boolean)

    snapshot contains capabilities to hotplug RAM; flag of type boolean

  • :nic_hot_plug (Boolean)

    snapshot contains capabilities to hotplug NIC; flag of type boolean

  • :nic_hot_un_plug (Boolean)

    snapshot contains capabilities to hotunplug NIC; flag of type boolean

Returns:

  • (Boolean)

    true on success, false otherwise



20
21
22
23
24
25
# File 'lib/profitbricks/snapshot.rb', line 20

def update(options = {})
  update_attributes_from_hash options
  options[:snapshot_name] = options.delete :name if options[:name]
  response = Profitbricks.request :update_snapshot, options.merge(:snapshot_id => self.id)
  return true
end