Class: OpenStack::AuthV10
Instance Method Summary collapse
-
#initialize(connection) ⇒ AuthV10
constructor
A new instance of AuthV10.
Constructor Details
#initialize(connection) ⇒ AuthV10
Returns a new instance of AuthV10.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/openstack/connection.rb', line 320 def initialize(connection) tries = connection.retries time = 3 hdrhash = { "X-Auth-User" => connection.authuser, "X-Auth-Key" => connection.authkey } begin server = Net::HTTP::Proxy(connection.proxy_host, connection.proxy_port).new(connection.auth_host, connection.auth_port) if connection.auth_scheme == "https" server.use_ssl = true server.verify_mode = OpenSSL::SSL::VERIFY_NONE # use the ca_cert if were given one, and make sure to verify! if !connection.ca_cert.nil? server.ca_file = connection.ca_cert server.verify_mode = OpenSSL::SSL::VERIFY_PEER end # explicitly set the SSL version to use server.ssl_version = connection.ssl_version if !connection.ssl_version.nil? end server.start rescue puts "Can't connect to the server: #{tries} tries to reconnect" if connection.is_debug sleep time += 1 retry unless (tries -= 1) <= 0 raise OpenStack::Exception::Connection, "Unable to connect to #{server}" end response = server.get(connection.auth_path, hdrhash) if (response.code =~ /^20./) connection.authtoken = response["x-auth-token"] case connection.service_type when "compute" uri = URI.parse(response["x-server-management-url"]) when "object-store" uri = URI.parse(response["x-storage-url"]) end raise OpenStack::Exception::Authentication, "Unexpected Response from #{connection.auth_host} - couldn't get service URLs: \"x-server-management-url\" is: #{response["x-server-management-url"]} and \"x-storage-url\" is: #{response["x-storage-url"]}" if (uri.host.nil? || uri.host=="") connection.service_host = uri.host connection.service_path = uri.path connection.service_port = uri.port connection.service_scheme = uri.scheme connection.authok = true else connection.authok = false raise OpenStack::Exception::Authentication, "Authentication failed with response code #{response.code}" end server.finish end |