Module: Fog::OpenStack
- Extended by:
- Provider
- Defined in:
- lib/fog/openstack.rb
Defined Under Namespace
Modules: Errors
Class Method Summary collapse
-
.authenticate_v1(options, connection_options = {}) ⇒ Object
legacy v1.0 style auth.
-
.authenticate_v2(options, connection_options = {}) ⇒ Object
keystone style auth.
Methods included from Provider
[], extended, service, services
Class Method Details
.authenticate_v1(options, connection_options = {}) ⇒ Object
legacy v1.0 style auth
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/openstack.rb', line 47 def self.authenticate_v1(, = {}) openstack_auth_url = [:openstack_auth_url] uri = URI.parse(openstack_auth_url) connection = Fog::Connection.new(openstack_auth_url, false, ) @openstack_api_key = [:openstack_api_key] @openstack_username = [:openstack_username] response = connection.request({ :expects => [200, 204], :headers => { 'X-Auth-Key' => @openstack_api_key, 'X-Auth-User' => @openstack_username }, :host => uri.host, :method => 'GET', :path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0' }) return { :token => response.headers['X-Auth-Token'], :server_management_url => response.headers['X-Server-Management-Url'] } end |
.authenticate_v2(options, connection_options = {}) ⇒ Object
keystone style auth
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fog/openstack.rb', line 72 def self.authenticate_v2(, = {}) openstack_auth_url = [:openstack_auth_url] uri = URI.parse(openstack_auth_url) connection = Fog::Connection.new(openstack_auth_url, false, ) @openstack_api_key = [:openstack_api_key] @openstack_username = [:openstack_username] @openstack_tenant = [:openstack_tenant] @compute_service_name = [:openstack_compute_service_name] req_body= { 'passwordCredentials' => { 'username' => @openstack_username, 'password' => @openstack_api_key } } req_body['tenantId'] = @openstack_tenant if @openstack_tenant response = connection.request({ :expects => [200, 204], :headers => {'Content-Type' => 'application/json'}, :body => MultiJson.encode(req_body), :host => uri.host, :method => 'POST', :path => (uri.path and not uri.path.empty?) ? uri.path : 'v2.0' }) body=MultiJson.decode(response.body) if body['auth']['serviceCatalog'] and body['auth']['serviceCatalog'][@compute_service_name] and body['auth']['serviceCatalog'][@compute_service_name][0] then mgmt_url = body['auth']['serviceCatalog'][@compute_service_name][0]['publicURL'] token = body['auth']['token']['id'] return { :token => token, :server_management_url => mgmt_url } else raise "Unable to parse service catalog." end end |