lib/vagrant-vcloud/driver/base.rb in vagrant-vcloud-0.4.0 vs lib/vagrant-vcloud/driver/base.rb in vagrant-vcloud-0.4.1
- old
+ new
@@ -295,11 +295,11 @@
clnt.ssl_config.verify_callback = proc { |ok, ctx|; true }
extheader = {}
extheader['accept'] = "application/*+xml;version=#{@api_version}"
- if !content_type.nil?
+ unless content_type.nil?
extheader['Content-Type'] = content_type
end
if @auth_key
extheader['x-vcloud-authorization'] = @auth_key
@@ -329,35 +329,40 @@
nil,
payload,
extheader
)
- if !response.ok?
- raise "Warning: unattended code #{response.status}" +
- " #{response.reason}"
+ unless response.ok?
+ if response.code == 400
+ error_message = Nokogiri.parse(response.body)
+ error = error_message.css('Error')
+ fail Errors::InvalidRequestError,
+ :message => error.first['message'].to_s
+ else
+ fail Errors::UnattendedCodeError,
+ :message => response.status
+ end
end
nicexml = Nokogiri.XML(response.body)
# Massive debug when LOG=DEBUG
# Using awesome_print to get nice XML output for readability
if @logger.level == 1
ap "[#{Time.now.ctime}] <- RECV #{response.status}"
# Just avoid the task spam.
- if !url.index('/task/')
+ unless url.index('/task/')
ap 'RECV HEADERS'
ap response.headers
ap 'RECV BODY'
ap nicexml
end
end
[Nokogiri.parse(response.body), response.headers]
- rescue SocketError
- raise 'Impossible to connect, verify endpoint'
- rescue Errno::EADDRNOTAVAIL
- raise 'Impossible to connect, verify endpoint'
+ rescue SocketError, Errno::EADDRNOTAVAIL
+ raise Errors::EndpointUnavailable, :endpoint => @api_url
end
end
##
# Upload a large file in configurable chunks, output an optional
@@ -430,11 +435,23 @@
'x-vcloud-authorization' => @auth_key,
'Content-Range' => content_range,
'Content-Length' => range_len.to_s
}
+ upload_request = "#{@host_url}#{upload_url}"
+
+ # Massive debug when LOG=DEBUG
+ # Using awesome_print to get nice XML output for better readability
+ if @logger.level == 1
+ ap "[#{Time.now.ctime}] -> SEND PUT #{upload_request}"
+ ap 'SEND HEADERS'
+ ap extheader
+ ap 'SEND BODY'
+ ap '<data omitted>'
+ end
+
begin
- upload_request = "#{@host_url}#{upload_url}"
+
# FIXME: Add debug on the return status of "connection"
# to enhance troubleshooting for this upload process.
# (tsugliani)
_connection = clnt.request(
'PUT',