1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/ibm/requests/storage/get_volume.rb

73 lines
2 KiB
Ruby
Raw Normal View History

2012-01-10 17:20:56 -05:00
module Fog
module Storage
class IBM
class Real
2011-04-26 22:49:05 -07:00
# Used to retrieve the specified storage volume for specified volume_id
#
# ==== Parameters
# * volume_id<~String> - Id of storage volume
2012-01-10 17:20:56 -05:00
#
# ==== Returns
# * response<~Excon::Response>:
2011-04-26 22:49:05 -07:00
# * body<~Hash>:
2012-01-10 17:20:56 -05:00
def get_volume(volume_id)
request(
:method => 'GET',
:expects => 200,
:path => "/storage/#{volume_id}"
)
end
end
2011-12-02 10:27:44 -08:00
class Mock
# For whatever reason, get_volume returns different data than an entry in list_volumes
def get_volume(volume_id)
response = Excon::Response.new
if volume_exists? volume_id
response.status = 200
response.body = format_get_volume_response_for(volume_id)
else
response.status = 404
end
response
end
# get_volume response doesn't contain instanceId
def format_get_volume_response_for(volume_id)
# If we aren't attached/ready, make us ready
ready_volume(volume_id) unless volume_attached? volume_id
self.data[:volumes][volume_id].reject { |k,v| k == 'instanceId' }
end
# The list_volumes response doesn't contain ioPrice
def format_list_volumes_response
self.data[:volumes].values.dup.map { |volume| volume.reject { |k,v| k == 'ioPrice'} }
end
def volume_exists?(volume_id)
self.data[:volumes].key? volume_id
end
# Checks if an volume is Active
def volume_ready?(volume_id)
self.data[:volumes][volume_id]['state'] == 4
end
def volume_attached?(volume_id)
self.data[:volumes][volume_id]['instanceId'] != "0"
end
# Sets volume status to Detached if it's not already set, and or attached
def ready_volume(volume_id)
# If not ready, make ready
self.data[:volumes][volume_id]['state'] = 4
end
end
2012-01-10 17:20:56 -05:00
end
end
end