Class: Fog::AWS::Compute::Volume

Inherits:
Model
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/fog/compute/models/aws/volume.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods included from Deprecation

deprecate, self_deprecate

Methods inherited from Model

#inspect, #reload, #to_json, #wait_for

Methods included from Fog::Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Attributes::InstanceMethods

#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume.



24
25
26
27
28
# File 'lib/fog/compute/models/aws/volume.rb', line 24

def initialize(attributes = {})
  # assign server first to prevent race condition with new_record?
  self.server = attributes.delete(:server)
  super
end

Instance Method Details

#destroyObject



30
31
32
33
34
35
# File 'lib/fog/compute/models/aws/volume.rb', line 30

def destroy
  requires :id

  connection.delete_volume(id)
  true
end

#ready?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/fog/compute/models/aws/volume.rb', line 37

def ready?
  state == 'available'
end

#saveObject

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/compute/models/aws/volume.rb', line 41

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
  requires :availability_zone, :size

  data = connection.create_volume(availability_zone, size, snapshot_id).body
  new_attributes = data.reject {|key,value| key == 'requestId'}
  merge_attributes(new_attributes)
  if @server
    self.server = @server
  end
  true
end

#server=(new_server) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/fog/compute/models/aws/volume.rb', line 54

def server=(new_server)
  if new_server
    attach(new_server)
  else
    detach
  end
end

#snapshotsObject



62
63
64
65
# File 'lib/fog/compute/models/aws/volume.rb', line 62

def snapshots
  requires :id
  connection.snapshots(:volume => self)
end