Class: OpenStack::Compute::AuthV20
- Inherits:
-
Object
- Object
- OpenStack::Compute::AuthV20
- Defined in:
- lib/openstack/compute/authentication.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(connection) ⇒ AuthV20
constructor
A new instance of AuthV20.
Constructor Details
#initialize(connection) ⇒ AuthV20
Returns a new instance of AuthV20.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/openstack/compute/authentication.rb', line 25 def initialize(connection) 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 end server.start rescue raise OpenStack::Compute::Exception::Connection, "Unable to connect to #{server}" end @uri = String.new if connection.auth_method == "password" auth_data = JSON.generate({ "auth" => { "passwordCredentials" => { "username" => connection.authuser, "password" => connection.authkey }, "tenantName" => connection.authtenant}}) elsif connection.auth_method == "rax-kskey" auth_data = JSON.generate({"auth" => {"RAX-KSKEY:apiKeyCredentials" => {"username" => connection.authuser, "apiKey" => connection.authkey}}}) else raise Exception::InvalidArgument, "Unrecognized auth method #{connection.auth_method}" end response = server.post(connection.auth_path.chomp("/")+"/tokens", auth_data, {'Content-Type' => 'application/json'}) if (response.code =~ /^20./) resp_data=JSON.parse(response.body) connection.authtoken = resp_data['access']['token']['id'] resp_data['access']['serviceCatalog'].each do |service| if connection.service_name check_service_name = connection.service_name else check_service_name = service['name'] end if service['type'] == connection.service_type and service['name'] == check_service_name endpoints = service["endpoints"] if connection.region endpoints.each do |ep| if ep["region"] and ep["region"].upcase == connection.region.upcase @uri = URI.parse(ep["publicURL"]) end end else @uri = URI.parse(endpoints[0]["publicURL"]) end if @uri == "" raise OpenStack::Compute::Exception::Authentication, "No API endpoint for region #{connection.region}" else connection.svrmgmthost = @uri.host connection.svrmgmtpath = @uri.path connection.svrmgmtport = @uri.port connection.svrmgmtscheme = @uri.scheme connection.authok = true end end end else connection.authtoken = false raise OpenStack::Compute::Exception::Authentication, "Authentication failed with response code #{response.code}" end server.finish end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
23 24 25 |
# File 'lib/openstack/compute/authentication.rb', line 23 def uri @uri end |