Class: Rackspace::Volume

Inherits:
Base
  • Object
show all
Defined in:
lib/rackspace/volume.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_CREDENTIALS

Instance Attribute Summary collapse

Attributes inherited from Base

#account, #credentials, #logger, #region

Instance Method Summary collapse

Methods inherited from Base

#log, #server_api, #storage_api

Constructor Details

#initialize(params) ⇒ Volume

Returns a new instance of Volume.



5
6
7
8
9
10
11
12
13
14
# File 'lib/rackspace/volume.rb', line 5

def initialize(params)
  super params
  if @volume_id = params[:volume_id]
    fetch_volume_by_id
  else
    @volume_type = params.fetch(:volume_type, SATA)
    @size        = params.fetch(:size, MIN_SIZE)
    @name        = params.fetch(:name)
  end
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



3
4
5
# File 'lib/rackspace/volume.rb', line 3

def device
  @device
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rackspace/volume.rb', line 3

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/rackspace/volume.rb', line 3

def size
  @size
end

#volume_idObject (readonly)

Returns the value of attribute volume_id.



3
4
5
# File 'lib/rackspace/volume.rb', line 3

def volume_id
  @volume_id
end

#volume_typeObject (readonly)

Returns the value of attribute volume_type.



3
4
5
# File 'lib/rackspace/volume.rb', line 3

def volume_type
  @volume_type
end

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
# File 'lib/rackspace/volume.rb', line 16

def create
  log "Creating #{size}GB #{volume_type} block storage volume: #{name}"
  storage_api.create(
    size:         size,
    name:         name,
    volume_type:  volume_type,
  )
  self
end

#destroyObject



26
27
28
29
30
# File 'lib/rackspace/volume.rb', line 26

def destroy
  log "Destroying volume #{name} in account #{}"
  volume.destroy
  self
end

#volumeObject



32
33
34
# File 'lib/rackspace/volume.rb', line 32

def volume
  @volume ||= storage_api.find_by_name(name)
end