mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[dns|rackspace] added attributes to list_domains; refactored rackspace errors to be shared with load balancers
This commit is contained in:
parent
fb940dd77a
commit
da35f1050d
5 changed files with 56 additions and 36 deletions
|
@ -45,7 +45,8 @@ module Fog
|
|||
response = @connection.request(params.merge!({
|
||||
:path => "#{@path}/#{params[:path]}"
|
||||
}))
|
||||
#TODO - Going to add rescues for the different expected errors
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise Fog::Rackspace::Errors::BadRequest.slurp error
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = MultiJson.decode(response.body)
|
||||
|
|
|
@ -3,10 +3,16 @@ module Fog
|
|||
class Rackspace
|
||||
class Real
|
||||
def list_domains(options={})
|
||||
|
||||
path = 'domains'
|
||||
if !options.empty?
|
||||
path = path + '?' + options.collect {|k,v| "#{k}=#{v}" }.join('&')
|
||||
end
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'domains'
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,9 +2,43 @@ require 'fog/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 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, 'cdn/rackspace')
|
||||
service(:compute, 'compute/rackspace')
|
||||
service(:storage, 'storage/rackspace')
|
||||
|
@ -33,6 +67,5 @@ module Fog
|
|||
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,39 +1,12 @@
|
|||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class LoadBalancers < Fog::Service
|
||||
|
||||
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 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
|
||||
#These references exist for backwards compatibility
|
||||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
||||
class BadRequest < Fog::Rackspace::Errors::BadRequest; end
|
||||
|
||||
DFW_ENDPOINT = 'https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/'
|
||||
ORD_ENDPOINT = 'https://ord.loadbalancers.api.rackspacecloud.com/v1.0/'
|
||||
|
|
|
@ -29,8 +29,15 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
tests('list_domains').formats(LIST_DOMAIN_FORMAT) do
|
||||
@service.list_domains.body
|
||||
end
|
||||
|
||||
tests('list_domains :limit => 5, :offset => 10, :domain => "hartsock" --> All possible attributes').formats(LIST_DOMAIN_FORMAT) do
|
||||
@service.list_domains(:limit => 5, :offset => 10, :domain => 'hartsock').body
|
||||
end
|
||||
end
|
||||
|
||||
tests( 'failure') do
|
||||
tests('list_domains :limit => 5, :offset => 8').raises(Fog::Rackspace::Errors::BadRequest) do
|
||||
@service.list_domains :limit => 5, :offset => 8
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue