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

[rackspace|compute_v2] updated compute_v2 to get the appropriate endpoint from the service catalog when an endpoint is specified via :rackspace_endpoint with one of the known constants (DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT); updated compute examples to use rackspace region

This commit is contained in:
Kyle Rames 2013-03-15 09:11:39 -05:00
parent f80aba6984
commit a3fb609379
10 changed files with 43 additions and 19 deletions

View file

@ -103,8 +103,7 @@ module Fog
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_endpoint = options[:rackspace_compute_url] || options[:rackspace_endpoint]
@rackspace_region = options[:rackspace_region] || :dfw
setup_custom_endpoint(options)
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
@ -124,7 +123,7 @@ module Fog
'Accept' => 'application/json',
'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}),
:host => @uri.host,
:host => endpoint_uri.host,
:path => "#{endpoint_uri.path}/#{params[:path]}"
}))
rescue Excon::Errors::NotFound => error
@ -170,16 +169,37 @@ module Fog
private
def deprecation_warnings(options)
Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_compute_url for custom endpoints") if options[:rackspace_endpoint]
def setup_custom_endpoint(options)
endpoint = options[:rackspace_compute_url] || options[:rackspace_endpoint]
if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication?
regions = @identity_service.service_catalog.display_service_regions(:cloudServersOpenStack)
Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid region for :rackspace_region are #{regions}.")
case endpoint
when DFW_ENDPOINT
@rackspace_region = :dfw
@rackspace_endpoint = nil
when ORD_ENDPOINT
@rackspace_region = :ord
@rackspace_endpoint = nil
when LON_ENDPOINT
@rackspace_region = :lon
@rackspace_endpoint = nil
else
# we are actually using a custom endpoint
@rackspace_endpoint = endpoint
@rackspace_region = options[:rackspace_region] || :dfw
end
end
def setup_endpoint(credentials)
def deprecation_warnings(options)
Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_compute_url for custom endpoints") if options[:rackspace_endpoint]
endpoint = options[:rackspace_compute_url] || options[:rackspace_endpoint]
if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(endpoint) && v2_authentication?
regions = @identity_service.service_catalog.display_service_regions(service_name)
Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid regions for :rackspace_region are #{regions}.")
end
end
def append_tenant_v1(credentials)
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || DFW_ENDPOINT
@ -189,7 +209,7 @@ module Fog
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
setup_endpoint credentials
append_tenant_v1 credentials
@auth_token = credentials['X-Auth-Token']
end
end

View file

@ -40,7 +40,7 @@ service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
# retrieve list of servers

View file

@ -29,7 +29,7 @@ service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
# pick the first flavor

View file

@ -40,7 +40,7 @@ service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
# retrieve list of images

View file

@ -40,7 +40,7 @@ service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
#retrieve list of servers

View file

@ -52,7 +52,7 @@ compute_service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
cbs_service = Fog::Rackspace::BlockStorage.new({

View file

@ -51,7 +51,7 @@ service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
#retrieve list of servers

View file

@ -40,7 +40,7 @@ compute_service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
cbs_service = Fog::Rackspace::BlockStorage.new({

View file

@ -30,7 +30,7 @@ service = Fog::Compute.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
# Pick the first flavor

View file

@ -30,7 +30,7 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
tests('variables populated') do
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
end
tests('custom endpoint') do
@ -76,6 +76,10 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
end
tests('specify old contstant style service endoint').succeeds do
@service = Fog::Compute::RackspaceV2.new :rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT
@service.list_flavors
end
tests('specify region') do
@service = Fog::Compute::RackspaceV2.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }