mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
replace Fog::Errors with Excon::Errors, add 409 conflicts for non-built rackspace server delete
This commit is contained in:
parent
f00f77638e
commit
fa1481e9f2
48 changed files with 56 additions and 52 deletions
|
@ -166,7 +166,6 @@ module Fog
|
||||||
response = @connection.request({
|
response = @connection.request({
|
||||||
:body => body,
|
:body => body,
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:error_parser => Fog::Errors::Parser.new,
|
|
||||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||||
:host => @host,
|
:host => @host,
|
||||||
:method => 'POST',
|
:method => 'POST',
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Fog
|
||||||
if public_ip
|
if public_ip
|
||||||
all(public_ip).first
|
all(public_ip).first
|
||||||
end
|
end
|
||||||
rescue Fog::Errors::BadRequest
|
rescue Excon::Errors::BadRequest
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Fog
|
||||||
if instance_id
|
if instance_id
|
||||||
all(instance_id).first
|
all(instance_id).first
|
||||||
end
|
end
|
||||||
rescue Fog::Errors::BadRequest
|
rescue Excon::Errors::BadRequest
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Fog
|
||||||
if key_name
|
if key_name
|
||||||
all(key_name).first
|
all(key_name).first
|
||||||
end
|
end
|
||||||
rescue Fog::Errors::BadRequest
|
rescue Excon::Errors::BadRequest
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Fog
|
||||||
if group_name
|
if group_name
|
||||||
all(group_name).first
|
all(group_name).first
|
||||||
end
|
end
|
||||||
rescue Fog::Errors::BadRequest
|
rescue Excon::Errors::BadRequest
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Fog
|
||||||
if snapshot_id
|
if snapshot_id
|
||||||
all(snapshot_id).first
|
all(snapshot_id).first
|
||||||
end
|
end
|
||||||
rescue Fog::Errors::BadRequest
|
rescue Excon::Errors::BadRequest
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Fog
|
||||||
if volume_id
|
if volume_id
|
||||||
all(volume_id).first
|
all(volume_id).first
|
||||||
end
|
end
|
||||||
rescue Fog::Errors::BadRequest
|
rescue Excon::Errors::BadRequest
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
||||||
def destroy
|
def destroy
|
||||||
connection.delete_bucket(@name)
|
connection.delete_bucket(@name)
|
||||||
true
|
true
|
||||||
rescue Fog::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ module Fog
|
||||||
}.merge!(object))
|
}.merge!(object))
|
||||||
end
|
end
|
||||||
bucket
|
bucket
|
||||||
rescue Fog::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ module Fog
|
||||||
:connection => connection
|
:connection => connection
|
||||||
}.merge!(object_data))
|
}.merge!(object_data))
|
||||||
object
|
object
|
||||||
rescue Fog::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ module Fog
|
||||||
:connection => connection
|
:connection => connection
|
||||||
}.merge!(object_data))
|
}.merge!(object_data))
|
||||||
object
|
object
|
||||||
rescue Fog::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,7 +60,7 @@ else
|
||||||
}.merge!(data)
|
}.merge!(data)
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
|
|
|
@ -48,7 +48,7 @@ else
|
||||||
}.merge!(data)
|
}.merge!(data)
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,7 +53,7 @@ else
|
||||||
}.merge!(data)
|
}.merge!(data)
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -104,7 +104,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,7 +66,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,7 +73,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,7 +50,7 @@ else
|
||||||
}.merge!(data)
|
}.merge!(data)
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,7 +72,7 @@ else
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,7 +66,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(200, 404, response))
|
raise(Excon::Errors.status_error(200, 404, response))
|
||||||
end
|
end
|
||||||
|
|
||||||
response
|
response
|
||||||
|
|
|
@ -35,10 +35,10 @@ else
|
||||||
response = Fog::Response.new
|
response = Fog::Response.new
|
||||||
if Fog::AWS::S3.data[:buckets][bucket_name].nil?
|
if Fog::AWS::S3.data[:buckets][bucket_name].nil?
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(204, 404, response))
|
raise(Excon::Errors.status_error(204, 404, response))
|
||||||
elsif Fog::AWS::S3.data[:buckets][bucket_name] && !Fog::AWS::S3.data[:buckets][bucket_name][:objects].empty?
|
elsif Fog::AWS::S3.data[:buckets][bucket_name] && !Fog::AWS::S3.data[:buckets][bucket_name][:objects].empty?
|
||||||
response.status = 409
|
response.status = 409
|
||||||
raise(Fog::Errors.status_error(204, 409, response))
|
raise(Excon::Errors.status_error(204, 409, response))
|
||||||
else
|
else
|
||||||
Fog::AWS::S3.data[:buckets].delete(bucket_name)
|
Fog::AWS::S3.data[:buckets].delete(bucket_name)
|
||||||
response.status = 204
|
response.status = 204
|
||||||
|
|
|
@ -40,7 +40,7 @@ else
|
||||||
bucket[:objects].delete(object_name)
|
bucket[:objects].delete(object_name)
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(204, 404, response))
|
raise(Excon::Errors.status_error(204, 404, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,7 +94,7 @@ else
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(200, 404, response))
|
raise(Excon::Errors.status_error(200, 404, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ else
|
||||||
response.body = {'LocationConstraint' => bucket['LocationConstraint'] }
|
response.body = {'LocationConstraint' => bucket['LocationConstraint'] }
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(200, 404, response))
|
raise(Excon::Errors.status_error(200, 404, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,7 +108,7 @@ else
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(200, 404, response))
|
raise(Excon::Errors.status_error(200, 404, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ else
|
||||||
response.body = { 'Payer' => bucket['Payer'] }
|
response.body = { 'Payer' => bucket['Payer'] }
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(200, 404, response))
|
raise(Excon::Errors.status_error(200, 404, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,7 +64,7 @@ else
|
||||||
bucket[:objects][object_name]['Content-Type'] = data[:headers]['Content-Type']
|
bucket[:objects][object_name]['Content-Type'] = data[:headers]['Content-Type']
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(200, 404, response))
|
raise(Excon::Errors.status_error(200, 404, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ else
|
||||||
bucket['Payer'] = payer
|
bucket['Payer'] = payer
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
raise(Fog::Errors.status_error(200, 404, response))
|
raise(Excon::Errors.status_error(200, 404, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,7 +60,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,7 +68,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
raise(Fog::Errors.status_error(200, 400, response))
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,7 +99,6 @@ module Fog
|
||||||
response = @connection.request({
|
response = @connection.request({
|
||||||
:block => params[:block],
|
:block => params[:block],
|
||||||
:body => params[:body],
|
:body => params[:body],
|
||||||
:error_parser => Fog::Errors::Parser.new,
|
|
||||||
:expects => params[:expects],
|
:expects => params[:expects],
|
||||||
:headers => params[:headers],
|
:headers => params[:headers],
|
||||||
:host => params[:host],
|
:host => params[:host],
|
||||||
|
|
|
@ -45,4 +45,4 @@ module Fog
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Fog::Rackspace.reload
|
Fog::Rackspace.reload
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Fog
|
||||||
|
|
||||||
def get(id)
|
def get(id)
|
||||||
connection.get_server_details(id)
|
connection.get_server_details(id)
|
||||||
rescue Fog::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,14 @@ else
|
||||||
|
|
||||||
def delete_server(id)
|
def delete_server(id)
|
||||||
response = Fog::Response.new
|
response = Fog::Response.new
|
||||||
if Fog::Rackspace::Servers.data[:servers].delete(id)
|
if server = Fog::Rackspace::Servers.data[:servers][id]
|
||||||
response.status = 202
|
if server['STATUS'] == 'BUILD'
|
||||||
|
response.status = 409
|
||||||
|
raise(Excon::Errors.status_error(200, 400, response))
|
||||||
|
else
|
||||||
|
Fog::Rackspace::Servers.delete(id)
|
||||||
|
response.status = 202
|
||||||
|
end
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,9 +4,9 @@ describe 'Rackspace::Servers.create_server' do
|
||||||
describe 'success' do
|
describe 'success' do
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
eventually(128) do
|
# eventually(128) do
|
||||||
servers.delete_server(@server_id)
|
servers.delete_server(@server_id)
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return proper attributes" do
|
it "should return proper attributes" do
|
||||||
|
|
Loading…
Reference in a new issue