class Fog::Storage::IBM::Mock
Public Class Methods
data()
click to toggle source
# File lib/fog/ibm/storage.rb, line 47 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :volumes => {}, } end end
new(options={})
click to toggle source
# File lib/fog/ibm/storage.rb, line 68 def initialize(options={}) @ibm_username = options[:ibm_username] @ibm_password = options[:ibm_password] @data = self.class.data[@ibm_username] end
reset()
click to toggle source
# File lib/fog/ibm/storage.rb, line 55 def self.reset @data = nil end
Public Instance Methods
create_volume(name, offering_id, format, location_id, size)
click to toggle source
# File lib/fog/ibm/requests/storage/create_volume.rb, line 45 def create_volume(name, offering_id, format, location_id, size) volume = Fog::IBM::Mock.create_volume(name, offering_id, format, location_id, size) self.data[:volumes][volume['id']] = volume response = Excon::Response.new response.status = 200 response.body = format_create_volume_response_for(volume['id']) response end
data()
click to toggle source
# File lib/fog/ibm/storage.rb, line 59 def data self.class.data[@ibm_username] end
delete_volume(volume_id)
click to toggle source
# File lib/fog/ibm/requests/storage/delete_volume.rb, line 24 def delete_volume(volume_id) response = Excon::Response.new if volume_exists? volume_id self.data[:volumes].delete volume_id response.status = 200 response.body = {"success"=>true} else response.status = 404 end response end
format_create_volume_response_for(volume_id)
click to toggle source
The create_volume
response doesn't contain ioPrice either
# File lib/fog/ibm/requests/storage/create_volume.rb, line 55 def format_create_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 == 'ioPrice' } end
format_get_volume_response_for(volume_id)
click to toggle source
get_volume
response doesn't contain instanceId
# File lib/fog/ibm/requests/storage/get_volume.rb, line 36 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
format_list_volumes_response()
click to toggle source
The list_volumes
response doesn't contain ioPrice
# File lib/fog/ibm/requests/storage/get_volume.rb, line 43 def format_list_volumes_response self.data[:volumes].values.dup.map { |volume| volume.reject { |k,v| k == 'ioPrice'} } end
get_volume(volume_id)
click to toggle source
For whatever reason, get_volume
returns different data than an entry in list_volumes
# File lib/fog/ibm/requests/storage/get_volume.rb, line 24 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
list_offerings()
click to toggle source
# File lib/fog/ibm/requests/storage/list_offerings.rb, line 37 def list_offerings response = Excon::Response.new response.status = 200 response.body = {"volumes"=> [{"name"=>"Small", "price"=> {"pricePerQuantity"=>1, "effectiveDate"=>-1, "rate"=>0.0384, "countryCode"=>"897", "unitOfMeasure"=>"UHR", "currencyCode"=>"USD"}, "location"=>"61", "id"=>"20001208", "formats"=> [{"label"=>"ext3", "id"=>"EXT3"}, {"label"=>"raw", "id"=>"RAW"}], "capacity"=>256}, {"name"=>"Small", "price"=> {"pricePerQuantity"=>1, "effectiveDate"=>-1, "rate"=>0.0384, "countryCode"=>"897", "unitOfMeasure"=>"UHR", "currencyCode"=>"USD"}, "location"=>"141", "id"=>"20001208", "formats"=> [{"label"=>"ext3", "id"=>"EXT3"}, {"label"=>"raw", "id"=>"RAW"}], "capacity"=>256}]}, response end
list_volumes()
click to toggle source
# File lib/fog/ibm/requests/storage/list_volumes.rb, line 34 def list_volumes response = Excon::Response.new response.status = 200 response.body = { 'volumes' => format_list_volumes_response } response end
ready_volume(volume_id)
click to toggle source
Sets volume status to Detached if it's not already set, and or attached
# File lib/fog/ibm/requests/storage/get_volume.rb, line 61 def ready_volume(volume_id) # If not ready, make ready self.data[:volumes][volume_id]['state'] = 4 end
reset_data()
click to toggle source
# File lib/fog/ibm/storage.rb, line 63 def reset_data self.class.data.delete(@ibm_username) @data = self.class.data[@ibm_username] end
volume_attached?(volume_id)
click to toggle source
# File lib/fog/ibm/requests/storage/get_volume.rb, line 56 def volume_attached?(volume_id) self.data[:volumes][volume_id]['instanceId'] != "0" end
volume_exists?(volume_id)
click to toggle source
# File lib/fog/ibm/requests/storage/get_volume.rb, line 47 def volume_exists?(volume_id) self.data[:volumes].key? volume_id end
volume_ready?(volume_id)
click to toggle source
Checks if an volume is Active
# File lib/fog/ibm/requests/storage/get_volume.rb, line 52 def volume_ready?(volume_id) self.data[:volumes][volume_id]['state'] == 4 end