2012-05-15 14:54:20 -04:00
|
|
|
require 'fog/ibm'
|
2012-01-10 17:20:56 -05:00
|
|
|
require 'fog/storage'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class IBM < Fog::Service
|
|
|
|
|
2012-02-28 16:28:45 -05:00
|
|
|
requires :ibm_username, :ibm_password
|
2012-01-10 17:20:56 -05:00
|
|
|
recognizes :location
|
|
|
|
|
|
|
|
model_path 'fog/ibm/models/storage'
|
|
|
|
|
|
|
|
model :offering
|
|
|
|
collection :offerings
|
|
|
|
model :volume
|
|
|
|
collection :volumes
|
|
|
|
|
|
|
|
request_path 'fog/ibm/requests/storage'
|
|
|
|
|
2012-01-17 12:02:12 -05:00
|
|
|
request :list_offerings
|
2012-01-10 17:20:56 -05:00
|
|
|
|
2012-01-17 12:02:12 -05:00
|
|
|
request :list_volumes
|
2012-01-10 17:20:56 -05:00
|
|
|
request :create_volume
|
|
|
|
request :delete_volume
|
|
|
|
request :get_volume
|
|
|
|
|
|
|
|
class Real
|
|
|
|
def initialize(options={})
|
2012-02-28 16:28:45 -05:00
|
|
|
@connection = Fog::IBM::Connection.new(options[:ibm_username], options[:ibm_password])
|
2012-01-10 17:20:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def request(options)
|
|
|
|
begin
|
|
|
|
@connection.request(options)
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
|
|
|
Fog::Storage::IBM::NotFound.slurp(error)
|
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
2012-02-13 09:59:12 -05:00
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {
|
|
|
|
:volumes => {},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
2012-02-28 16:28:45 -05:00
|
|
|
self.class.data[@ibm_username]
|
2012-02-13 09:59:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
2012-02-28 16:28:45 -05:00
|
|
|
self.class.data.delete(@ibm_username)
|
|
|
|
@data = self.class.data[@ibm_username]
|
2012-02-13 09:59:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
2012-02-28 16:28:45 -05:00
|
|
|
@ibm_username = options[:ibm_username]
|
2012-02-13 09:59:12 -05:00
|
|
|
@ibm_password = options[:ibm_password]
|
2012-02-28 16:28:45 -05:00
|
|
|
@data = self.class.data[@ibm_username]
|
2012-01-10 17:20:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|