Class: Fog::Rackspace::BlockStorage::Volume

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/rackspace/models/block_storage/volume.rb

Constant Summary collapse

AVAILABLE =
'available'
ATTACHING =
'attaching'
CREATING =
'creating'
DELETING =
'deleting'
ERROR =
'error'
ERROR_DELETING =
'error_deleting'
IN_USE =
'in-use'

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

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

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#attached?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 30

def attached?
  state == IN_USE
end

#create_snapshot(options = {}) ⇒ Object



38
39
40
41
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 38

def create_snapshot(options={})
  requires :identity
  service.snapshots.create(options.merge(:volume_id => identity))
end

#destroyObject



56
57
58
59
60
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 56

def destroy
  requires :identity
  service.delete_volume(identity)
  true
end

#ready?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 26

def ready?
  state == AVAILABLE
end

#saveObject

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 43

def save
  requires :size
  raise IdentifierTaken.new('Resaving may cause a duplicate volume to be created') if persisted?
  data = service.create_volume(size, {
    :display_name => display_name,
    :display_description => display_description,
    :volume_type => volume_type,
    :availability_zone => availability_zone
  })
  merge_attributes(data.body['volume'])
  true
end

#snapshotsObject



34
35
36
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 34

def snapshots
  service.snapshots.select { |s| s.volume_id == identity }
end