Class: Fog::Compute::ProfitBricks::Volume

Inherits:
Models::ProfitBricks::Base show all
Includes:
Helpers::ProfitBricks::DataHelper
Defined in:
lib/fog/profitbricks/models/compute/volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ProfitBricks::DataHelper

#flatten

Methods inherited from Models::ProfitBricks::Base

#failed?, #ready?, #request_status, #wait_for

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume.


46
47
48
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 46

def initialize(attributes = {})
  super
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options


44
45
46
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 44

def options
  @options
end

Instance Method Details

#create_snapshot(name, description = '') ⇒ Object


104
105
106
107
108
109
110
111
112
113
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 104

def create_snapshot(name, description = '')
  requires :datacenter_id, :id

  options = {}
  options[:name] = name if name
  options[:description] = description if description && description != ''

  service.create_volume_snapshot(datacenter_id, id, options)
  true
end

#deleteObject


82
83
84
85
86
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 82

def delete
  requires :datacenter_id, :id
  service.delete_volume(datacenter_id, id)
  true
end

#reloadObject


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 88

def reload
  requires :datacenter_id, :id

  data = begin
    collection.get(datacenter_id, id)
  rescue Excon::Errors::SocketError
    nil
  end

  return unless data

  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#restore_snapshot(snapshot_id) ⇒ Object


115
116
117
118
119
120
121
122
123
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 115

def restore_snapshot(snapshot_id)
  requires :datacenter_id, :id

  options = {}
  options[:snapshot_id] = snapshot_id if snapshot_id

  service.restore_volume_snapshot(datacenter_id, id, options)
  true
end

#saveObject


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 50

def save
  requires :datacenter_id, :size, :type

  options = {}
  options[:name]              = name if name
  options[:size]              = size
  options[:bus]               = bus if bus
  options[:image]             = image if image
  options[:imageAlias]        = image_alias if image_alias
  options[:type]              = type
  options[:licenceType]       = licence_type if licence_type
  options[:imagePassword]     = image_password if image_password
  options[:sshKeys]           = ssh_keys if ssh_keys
  options[:availabilityZone]  = availability_zone if availability_zone

  data = service.create_volume(datacenter_id, options)
  merge_attributes(flatten(data.body))
  true
end

#updateObject


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fog/profitbricks/models/compute/volume.rb', line 70

def update
  requires :datacenter_id, :id

  options = {}
  options[:name] = name if name
  options[:size] = size if size

  data = service.update_volume(datacenter_id, id, options)
  merge_attributes(flatten(data.body))
  true
end