class Rackspace::Volume
Attributes
device[R]
name[R]
size[R]
volume_id[R]
volume_type[R]
Public Class Methods
new(params)
click to toggle source
Calls superclass method
Rackspace::Base::new
# 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
Public Instance Methods
create()
click to toggle source
# 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
destroy()
click to toggle source
# File lib/rackspace/volume.rb, line 26 def destroy log "Destroying volume #{name} in account #{account}" volume.destroy self end
volume()
click to toggle source
# File lib/rackspace/volume.rb, line 32 def volume @volume ||= storage_api.find_by_name(name) end
Private Instance Methods
fetch_volume_by_id()
click to toggle source
Find an existing volume by its volume_id
# File lib/rackspace/volume.rb, line 39 def fetch_volume_by_id vol = storage_api.find_by_id(volume_id) data = vol.body.fetch("volume") @name = data.fetch('display_name') @volume_type = data.fetch('volume_type') @size = data.fetch('size') # Sometimes the Rackspace API takes time to update, # and newly-attached volumes don't report any attachments # yet. attachments = data.fetch('attachments') if attachments.any? @device = attachments.first.fetch('device') end end