Skip to content

Instantly share code, notes, and snippets.

@elight

elight/compute.rb

Created May 2, 2014
Embed
What would you like to do?
def request(params)
begin
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
:path => "#{@path}/#{@tenant_id}/#{params[:path]}",
:query => params[:query]
}))
rescue Excon::Errors::Unauthorized => error
if error.response.body != 'Bad username or password' # token expiration
@openstack_must_reauthenticate = true
authenticate
retry
else # Bad Credentials
raise error
end
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Compute::OpenStack::NotFound.slurp(error)
else
error
end
end
if !response.body.empty? and response.get_header('Content-Type') == 'application/json'
response.body = Fog::JSON.decode(response.body)
end
response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment