lib/fog/rackspace/compute.rb in fog-1.10.0 vs lib/fog/rackspace/compute.rb in fog-1.10.1
- old
+ new
@@ -5,11 +5,11 @@
module Compute
class Rackspace < Fog::Service
requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent
- recognizes :rackspace_auth_token, :rackspace_management_url
+ recognizes :rackspace_auth_token, :rackspace_management_url, :rackspace_compute_v1_url, :rackspace_region
model_path 'fog/rackspace/models/compute'
model :flavor
collection :flavors
model :image
@@ -39,11 +39,11 @@
request :revert_resized_server
request :resize_server
request :server_action
request :update_server
- class Mock
+ class Mock < Fog::Rackspace::Service
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:last_modified => {
@@ -178,25 +178,25 @@
self.class.data.delete(@rackspace_username)
end
end
- class Real
+ class Real < Fog::Rackspace::Service
def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_servicenet = options[:rackspace_servicenet]
@rackspace_auth_token = options[:rackspace_auth_token]
- @rackspace_management_url = options[:rackspace_management_url]
+ @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_v1_url] || options[:rackspace_management_url])
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
authenticate
- Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true
+ Excon.defaults[:ssl_verify_peer] = false if service_net?
@persistent = options[:persistent] || false
- @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
+ @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end
def reload
@connection.reset
end
@@ -204,14 +204,14 @@
def request(params)
begin
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
- 'X-Auth-Token' => @auth_token
+ 'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}),
- :host => @host,
- :path => "#{@path}/#{params[:path]}",
+ :host => endpoint_uri.host,
+ :path => "#{endpoint_uri.path}/#{params[:path]}",
:query => ('ignore_awful_caching' << Time.now.to_i.to_s)
}))
rescue Excon::Errors::Unauthorized => error
if error.response.body != 'Bad username or password' # token expiration
@rackspace_must_reauthenticate = true
@@ -232,30 +232,55 @@
response.body = Fog::JSON.decode(response.body)
end
response
end
- private
- def authenticate
- if @rackspace_must_reauthenticate || @rackspace_auth_token.nil?
- options = {
- :rackspace_api_key => @rackspace_api_key,
- :rackspace_username => @rackspace_username,
- :rackspace_auth_url => @rackspace_auth_url
- }
- credentials = Fog::Rackspace.authenticate(options, @connection_options)
- @auth_token = credentials['X-Auth-Token']
- uri = URI.parse(credentials['X-Server-Management-Url'])
- else
- @auth_token = @rackspace_auth_token
- uri = URI.parse(@rackspace_management_url)
- end
- @host = @rackspace_servicenet == true ? "snet-#{uri.host}" : uri.host
- @path = uri.path
- @port = uri.port
- @scheme = uri.scheme
+ def service_net?
+ @rackspace_servicenet == true
end
+
+ def authenticate
+ if @rackspace_must_reauthenticate || @rackspace_auth_token.nil?
+ options = {
+ :rackspace_api_key => @rackspace_api_key,
+ :rackspace_username => @rackspace_username,
+ :rackspace_auth_url => @rackspace_auth_url
+ }
+ super(options)
+ else
+ @auth_token = @rackspace_auth_token
+ @uri = URI.parse(@rackspace_endpoint)
+ end
+ end
+
+ def service_name
+ :cloudServers
+ end
+
+ def region
+ @rackspace_region
+ end
+
+ def endpoint_uri(service_endpoint_url=nil)
+ return @uri if @uri
+
+ @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_compute_v1_url)
+ @uri.host = "snet-#{@uri.host}" if service_net?
+ @uri
+ end
+
+ private
+
+ def deprecation_warnings(options)
+ Fog::Logger.deprecation("The :rackspace_management_url option is deprecated. Please use :rackspace_compute_v1_url for custom endpoints") if options[:rackspace_management_url]
+ end
+
+ def authenticate_v1(options)
+ credentials = Fog::Rackspace.authenticate(options, @connection_options)
+ endpoint_uri credentials['X-Server-Management-Url']
+ @auth_token = credentials['X-Auth-Token']
+ end
end
end
end
end