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.



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

def initialize(attributes = {})
  super
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

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



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

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



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

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

#reloadObject



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

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



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

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



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

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[: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



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

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