# File lib/deltacloud/api.rb, line 80 def initialize(driver_name, opts={}, &block) Thread.current[:driver] = driver_name.to_s Thread.current[:provider] = opts[:provider] @backend = driver opts[:user] ||= 'mockuser' opts[:password] ||= 'mockpassword' @credentials = OpenStruct.new(:user => opts[:user], :password => opts[:password]) yield backend if block_given? end
# File lib/deltacloud/api.rb, line 98 def current_driver Thread.current[:driver] end
# File lib/deltacloud/api.rb, line 94 def current_provider Thread.current[:provider] end
# File lib/deltacloud/api.rb, line 114 def method_missing(name, *args) return super unless backend.respond_to? name begin params = ([@credentials] + args).flatten backend.send(name, *params) rescue ArgumentError => e puts "[W] Wrong arguments for #{name}. Omitting credentials injection. (#{e.message})" backend.send(name, *args) end end
# File lib/deltacloud/api.rb, line 110 def provider(opts={}) providers.find { |p| p.id == opts[:id] } end
# File lib/deltacloud/api.rb, line 102 def providers if backend.respond_to? :providers backend.providers(@credentials) else Deltacloud.drivers[current_driver.to_sym] end end
# File lib/deltacloud/api.rb, line 90 def version Deltacloud::API_VERSION end