1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[OpenStack|compute] fix v2.0 auth endpoints

This fixes how paths and regexps work for less common cases (eg: having
and auth endpoint that is /v2.0/tokens.json).

Serialization to/from json and setting content-type header are added.

No longer silently converts nova api endpoints to 1.1, but errors instead.  You
should be using keystone's service catalog in conjunction with
@openstack_compute_service_name.
This commit is contained in:
Todd Willey 2011-10-11 16:59:12 -04:00
parent 87d07b7787
commit e3d4f3336c
2 changed files with 12 additions and 8 deletions

View file

@ -88,12 +88,13 @@ module Fog
response = connection.request({
:expects => [200, 204],
:body => req_body,
:headers => {'Content-Type' => 'application/json'},
:body => MultiJson.encode(req_body),
:host => uri.host,
:method => 'GET',
:method => 'POST',
:path => (uri.path and not uri.path.empty?) ? uri.path : 'v2.0'
})
body=response.body
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']

View file

@ -6,8 +6,8 @@ module Fog
module Compute
class OpenStack < Fog::Service
requires :openstack_api_key, :openstack_username, :openstack_auth_url, :openstack_tenant
recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_compute_service_name
requires :openstack_api_key, :openstack_username, :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_compute_service_name, :openstack_tenant
model_path 'fog/openstack/models/compute'
model :flavor
@ -167,7 +167,7 @@ module Fog
:openstack_tenant => @openstack_tenant,
:openstack_compute_service_name => @openstack_compute_service_name
}
if @openstack_auth_url =~ /.*v2.0\/?$/
if @openstack_auth_url =~ /\/v2.0\//
credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
else
credentials = Fog::OpenStack.authenticate_v1(options, @connection_options)
@ -181,8 +181,11 @@ module Fog
end
@host = uri.host
@path = uri.path
# Force URL into v1.1 namespace (what this binding supports)
@path.sub!(/\/.*\/?/, '/v1.1/')
@path.sub!(/\/$/, '')
unless @path.match(/1\.1/)
raise Fog::Compute::OpenStack::ServiceUnavailable.new(
"OpenStack binding only supports version 1.1")
end
# Add tenant
@path += @openstack_tenant if @openstack_tenant
@port = uri.port