Method: OpenStack::Connection#csreq

Defined in:
lib/openstack/connection.rb

#csreq(method, server, path, port, scheme, headers = {}, data = nil, attempts = 0, &block) ⇒ Object

This method actually makes the HTTP REST calls out to the server



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/openstack/connection.rb', line 144

def csreq(method,server,path,port,scheme,headers = {},data = nil,attempts = 0, &block) # :nodoc:
  hdrhash = headerprep(headers)
  start_http(server,path,port,scheme,hdrhash)
  request = Net::HTTP.const_get(method.to_s.capitalize).new(path,hdrhash)
  request.body = data
  if block_given?
    response =  @http[server].request(request) do |res|
      res.read_body do |b|
        yield b
      end
    end
  else
    response = @http[server].request(request)
  end
  if @is_debug
      puts "REQUEST: #{method} => #{path}"
      puts data if data
      puts "RESPONSE: #{response.body}"
      puts '----------------------------------------'
  end
  raise OpenStack::Exception::ExpiredAuthToken if response.code == "401"
  response
rescue Errno::EPIPE, Timeout::Error, Errno::EINVAL, EOFError
  # Server closed the connection, retry
  raise OpenStack::Exception::Connection, "Unable to reconnect to #{server} after #{attempts} attempts" if attempts >= 5
  attempts += 1
  @http[server].finish if @http[server].started?
  start_http(server,path,port,scheme,headers)
  retry
rescue OpenStack::Exception::ExpiredAuthToken
  raise OpenStack::Exception::Connection, "Authentication token expired and you have requested not to retry" if @retry_auth == false
  OpenStack::Authentication.init(self)
  retry
end