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 collapse

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 Attribute Details

#attachmentsArray<Hash> (readonly)

Returns an array of hashes containing attachment information

Returns:

  • (Array<Hash>)

    returns an array of hashes containing attachment information



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

attribute :attachments

#availability_zoneString (readonly)

Returns region of the volume.

Returns:

  • (String)

    region of the volume



49
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 49

attribute :availability_zone

#created_atString (readonly)

Returns volume creation date.

Returns:

  • (String)

    volume creation date



21
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 21

attribute :created_at, :aliases => 'createdAt'

#display_descriptionString

Returns display description of volume.

Returns:

  • (String)

    display description of volume



33
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 33

attribute :display_description

#display_nameString

Returns display name of volume.

Returns:

  • (String)

    display name of volume



29
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 29

attribute :display_name

#idString (readonly)

Returns The volume id.

Returns:



17
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 17

identity :id

#sizeString

Returns size of the volume in GB (100 GB minimum).

Returns:

  • (String)

    size of the volume in GB (100 GB minimum)



37
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 37

attribute :size

#stateString (readonly)

Returns volume status.

Returns:



25
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 25

attribute :state, :aliases => 'status'

#volume_typeString

Returns type of volume.

Returns:



45
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 45

attribute :volume_type

Instance Method Details

#attached?Boolean

Returns true if the volume is attached

Returns:

  • (Boolean)

    true if the volume is attached



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

def attached?
  state == IN_USE
end

#create_snapshot(options = {}) ⇒ Fog::Rackspace::BlockStorage::Snapshot

Note:

All writes to the volume should be flushed before creating the snapshot, either by un-mounting any file systems on the volume or by detaching the volume.

Creates a snapshot from the current volume

Parameters:

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

Options Hash (options):

  • :display_name (String)

    of snapshot

  • :display_description (String)

    of snapshot

  • :force (Boolean)
    • If set to true, snapshot will be taken even if volume is still mounted.

Returns:

Raises:

See Also:



86
87
88
89
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 86

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

#destroyBoolean

Note:

You cannot delete a volume until all of its dependent snaphosts have been deleted.

Destroys Volume



121
122
123
124
125
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 121

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

#ready?Boolean

Returns true if the volume is in a ready state

Returns:

  • (Boolean)

    returns true if volume is in a ready state



53
54
55
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 53

def ready?
  state == AVAILABLE
end

#saveBoolean

Note:

A volume object cannot be updated

Creates volume



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 100

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

#snapshotsFog::Rackspace::BlockStorage::Snapshots

Returns a list of snapshots associated with the volume



69
70
71
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 69

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