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/rackspace.rb
geemus b2c8ff0388 [core] work toward separate requires
Should facilitate the following:

    require 'fog/aws'
    require 'fog/compute'
    require 'fog/aws/compute'

I think once you `require 'rubygems'` those should work.

further cleanup should reduce common requires (ie nokogiri)
2011-08-31 15:52:53 -05:00

74 lines
2.4 KiB
Ruby

require(File.expand_path(File.join(File.dirname(__FILE__), 'core')))
module Fog
module Rackspace
extend Fog::Provider
module Errors
class ServiceError < Fog::Errors::Error
attr_reader :response_data
def self.slurp(error)
if error.response.body.empty?
data = nil
message = nil
else
data = MultiJson.decode(error.response.body)
message = data['message']
end
new_error = super(error, message)
new_error.instance_variable_set(:@response_data, data)
new_error
end
end
class InternalServerError < ServiceError; end
class Conflict < ServiceError; end
class NotFound < ServiceError; end
class ServiceUnavailable < ServiceError; end
class BadRequest < ServiceError
#TODO - Need to find a bette way to print out these validation errors when they are thrown
attr_reader :validation_errors
def self.slurp(error)
new_error = super(error)
unless new_error.response_data.nil?
new_error.instance_variable_set(:@validation_errors, new_error.response_data['validationErrors'])
end
new_error
end
end
end
service(:cdn, 'rackspace/cdn')
service(:compute, 'rackspace/compute')
service(:dns, 'rackspace/dns')
service(:storage, 'rackspace/storage')
service(:load_balancers, 'rackspace/load_balancers')
def self.authenticate(options)
rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com"
url = rackspace_auth_url.match(/^https?:/) ? \
rackspace_auth_url : 'https://' + rackspace_auth_url
uri = URI.parse(url)
connection = Fog::Connection.new(url)
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
response = connection.request({
:expects => [200, 204],
:headers => {
'X-Auth-Key' => @rackspace_api_key,
'X-Auth-User' => @rackspace_username
},
:host => uri.host,
:method => 'GET',
:path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0'
})
response.headers.reject do |key, value|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
end
end
end
end