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

Instance Method Summary collapse

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

#image_idString

Returns The ID of an image used to create a bootable volume.

Returns:

  • (String)

    The ID of an image used to create a bootable volume.



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

attribute :image_id, :aliases => ['image', 'imageRef'], :squash => '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



63
64
65
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 63

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:



89
90
91
92
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 89

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

Returns:

  • (Boolean)

    returns true if volume was deleted

Raises:

See Also:



126
127
128
129
130
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 126

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



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

def ready?
  state == AVAILABLE
end

#saveBoolean

Note:

A volume object cannot be updated

Creates volume

Returns:

  • (Boolean)

    returns true if volume was successfully created

Raises:

See Also:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 103

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,
    :snapshot_id => attributes[:snapshot_id],
    :image_id => attributes[:image_id]
  })
  merge_attributes(data.body['volume'])
  true
end

#snapshotsFog::Rackspace::BlockStorage::Snapshots

Returns a list of snapshots associated with the volume



73
74
75
# File 'lib/fog/rackspace/models/block_storage/volume.rb', line 73

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