diff --git a/lib/fog/openstack/baremetal.rb b/lib/fog/openstack/baremetal.rb index ee71ad013..4eabc5953 100644 --- a/lib/fog/openstack/baremetal.rb +++ b/lib/fog/openstack/baremetal.rb @@ -6,10 +6,15 @@ module Fog SUPPORTED_VERSIONS = /(.)*/ requires :openstack_auth_url - recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_type, :openstack_service_name, :openstack_tenant, - :openstack_api_key, :openstack_username, - :current_user, :current_tenant, :openstack_endpoint_type, :openstack_region + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, + :current_user, :current_tenant, :openstack_region, + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id ## MODELS # @@ -241,55 +246,29 @@ module Fog end class Real - attr_reader :current_user - attr_reader :current_tenant + include Fog::OpenStack::Core def initialize(options={}) - @openstack_auth_token = options[:openstack_auth_token] + initialize_identity options - unless @openstack_auth_token - missing_credentials = Array.new - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] - - missing_credentials << :openstack_api_key unless @openstack_api_key - missing_credentials << :openstack_username unless @openstack_username - raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? - end - - @openstack_tenant = options[:openstack_tenant] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) - @openstack_management_url = options[:openstack_management_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['baremetal'] - @openstack_service_name = options[:openstack_service_name] - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - @openstack_region = options[:openstack_region] + @openstack_service_type = options[:openstack_service_type] || ['baremetal'] + @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} - @current_user = options[:current_user] - @current_tenant = options[:current_tenant] - authenticate + unless @path.match(SUPPORTED_VERSIONS) + @path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS, + @openstack_management_uri, + @auth_token, + @connection_options) + end + @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def credentials - { :provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :current_user => @current_user, - :current_tenant => @current_tenant } - end - - def reload - @connection.reset - end - def request(params) begin response = @connection.request(params.merge({ @@ -323,47 +302,6 @@ module Fog private - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_tenant => @openstack_tenant, - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_auth_uri => @openstack_auth_uri, - :openstack_region => @openstack_region, - :openstack_auth_token => @openstack_must_reauthenticate ? nil : @openstack_auth_token, - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_endpoint_type => @openstack_endpoint_type - } - - credentials = Fog::OpenStack.authenticate(options, @connection_options) - - @current_user = credentials[:user] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @openstack_management_url = credentials[:server_management_url] - uri = URI.parse(@openstack_management_url) - else - @auth_token = @openstack_auth_token - uri = URI.parse(@openstack_management_url) - end - - @host = uri.host - @path = uri.path - @path.sub!(/\/$/, '') - unless @path.match(SUPPORTED_VERSIONS) - @path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS, - uri, - @auth_token, - @connection_options) - end - @port = uri.port - @scheme = uri.scheme - true - end end end end diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index 1d95f9d21..8c95cb62f 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -327,30 +327,29 @@ module Fog end class Real - include Fog::OpenStack::Core def initialize(options={}) initialize_identity options @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity' - @openstack_service_type = options[:openstack_service_type] || ['nova', 'compute'] - @openstack_service_name = options[:openstack_service_name] - @connection_options = options[:connection_options] || {} + @openstack_service_type = options[:openstack_service_type] || ['nova', 'compute'] + @openstack_service_name = options[:openstack_service_name] - authenticate_compute + @connection_options = options[:connection_options] || {} + + authenticate + + unless @path.match(/1\.1|v2/) + raise Fog::OpenStack::Errors::ServiceUnavailable.new( + "OpenStack compute binding only supports version 2 (a.k.a. 1.1)") + end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - - - def reload - @connection.reset - end - def request(params) begin response = @connection.request(params.merge({ @@ -365,7 +364,7 @@ module Fog rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true - authenticate_compute + authenticate retry else # Bad Credentials raise error @@ -388,28 +387,6 @@ module Fog private - def authenticate_compute - authenticate - - uri = URI.parse(@openstack_management_url) - @host = uri.host - @path = uri.path - - @path.sub!(/\/$/, '') - unless @path.match(/1\.1|v2/) - raise Fog::OpenStack::Errors::ServiceUnavailable.new( - "OpenStack compute binding only supports version 2 (a.k.a. 1.1)") - end - - # Not all implementations have identity service in the catalog - if @openstack_identity_public_endpoint || @openstack_management_url - @identity_connection = Fog::Core::Connection.new( - @openstack_identity_public_endpoint || @openstack_management_url, - false, @connection_options) - end - - true - end end end end diff --git a/lib/fog/openstack/core.rb b/lib/fog/openstack/core.rb index 91a9461ee..a34217b87 100644 --- a/lib/fog/openstack/core.rb +++ b/lib/fog/openstack/core.rb @@ -107,6 +107,10 @@ module Fog openstack_options.merge options end + def reload + @connection.reset + end + private def openstack_options @@ -142,8 +146,17 @@ module Fog @host = @openstack_management_uri.host @path = @openstack_management_uri.path + @path.sub!(/\/$/, '') @port = @openstack_management_uri.port @scheme = @openstack_management_uri.scheme + + # Not all implementations have identity service in the catalog + if @openstack_identity_public_endpoint || @openstack_management_url + @identity_connection = Fog::Core::Connection.new( + @openstack_identity_public_endpoint || @openstack_management_url, + false, @connection_options) + end + true end end diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index 1514a1056..b4b2fae4a 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -22,53 +22,42 @@ module Fog end module Common + attr_reader :unscoped_token - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_userid => @openstack_userid, - :openstack_domain_name => @openstack_domain_name, - :openstack_domain_id => @openstack_domain_id, - :openstack_project_name => @openstack_project_name, - :openstack_auth_token => @openstack_must_reauthenticate ? nil : @openstack_auth_token, - :openstack_auth_uri => @openstack_auth_uri, - :openstack_tenant => @openstack_tenant, - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_endpoint_type => @openstack_endpoint_type, - :openstack_region => @openstack_region - } + include Fog::OpenStack::Core - credentials = Fog::OpenStack.authenticate(options, @connection_options) + def request(params) + retried = false + begin + response = @connection.request(params.merge({ + :headers => params.fetch(:headers,{}).merge({ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'X-Auth-Token' => @auth_token + }), + :path => "#{@path}/#{params[:path]}" + })) + rescue Excon::Errors::Unauthorized => error + raise if retried + retried = true - @current_user = credentials[:user] - @current_user_id = credentials[:current_user_id] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @openstack_management_url = credentials[:server_management_url] - @openstack_current_user_id = credentials[:current_user_id] - @unscoped_token = credentials[:unscoped_token] - uri = URI.parse(@openstack_management_url) - else - @auth_token = @openstack_auth_token - uri = URI.parse(@openstack_management_url) + @openstack_must_reauthenticate = true + authenticate + retry + rescue Excon::Errors::HTTPStatusError => error + raise case error + when Excon::Errors::NotFound + Fog::Identity::OpenStack::NotFound.slurp(error) + else + error + end end - - @host = uri.host - @path = uri.path - @path.sub!(/\/$/, '') - @port = uri.port - @scheme = uri.scheme - true + unless response.body.empty? + response.body = Fog::JSON.decode(response.body) + end + response end - end end - - end end diff --git a/lib/fog/openstack/identity_v2.rb b/lib/fog/openstack/identity_v2.rb index e1db204ba..c61bcb2df 100644 --- a/lib/fog/openstack/identity_v2.rb +++ b/lib/fog/openstack/identity_v2.rb @@ -7,11 +7,15 @@ module Fog class V2 < Fog::Service requires :openstack_auth_url - recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_type, :openstack_service_name, :openstack_tenant, - :openstack_api_key, :openstack_username, :openstack_current_user_id, - :current_user, :current_tenant, - :openstack_endpoint_type, :openstack_region + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, + :current_user, :current_tenant, :openstack_region, + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id model_path 'fog/openstack/models/identity_v2' model :tenant @@ -166,97 +170,23 @@ module Fog end class Real - attr_reader :current_user - attr_reader :current_tenant - attr_reader :unscoped_token - include Fog::Identity::OpenStack::Common def initialize(options={}) - @openstack_auth_token = options[:openstack_auth_token] + initialize_identity options - unless @openstack_auth_token - missing_credentials = Array.new - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] - @openstack_region = options[:openstack_region] + @openstack_service_type = options[:openstack_service_type] || ['identity'] + @openstack_service_name = options[:openstack_service_name] - missing_credentials << :openstack_api_key unless @openstack_api_key - missing_credentials << :openstack_username unless @openstack_username - raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? - end + @connection_options = options[:connection_options] || {} - @openstack_tenant = options[:openstack_tenant] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) - @openstack_management_url = options[:openstack_management_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['identity'] - @openstack_service_name = options[:openstack_service_name] - - @connection_options = options[:connection_options] || {} - - @openstack_current_user_id = options[:openstack_current_user_id] - - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - - @current_user = options[:current_user] - @current_tenant = options[:current_tenant] + @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' authenticate @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - - def credentials - {:provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :openstack_current_user_id => @openstack_current_user_id, - :current_user => @current_user, - :current_tenant => @current_tenant} - end - - def reload - @connection.reset - end - - def request(params) - retried = false - begin - response = @connection.request(params.merge({ - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - 'X-Auth-Token' => @auth_token - }.merge!(params[:headers] || {}), - :path => "#{@path}/#{params[:path]}" #, - })) - rescue Excon::Errors::Unauthorized => error - raise if retried - retried = true - - @openstack_must_reauthenticate = true - authenticate - retry - rescue Excon::Errors::HTTPStatusError => error - raise case error - when Excon::Errors::NotFound - Fog::Identity::OpenStack::NotFound.slurp(error) - else - error - end - end - unless response.body.empty? - response.body = Fog::JSON.decode(response.body) - end - response - end - - private - - end end end diff --git a/lib/fog/openstack/identity_v3.rb b/lib/fog/openstack/identity_v3.rb index bc38ee04f..a561cc76c 100644 --- a/lib/fog/openstack/identity_v3.rb +++ b/lib/fog/openstack/identity_v3.rb @@ -148,71 +148,24 @@ module Fog end class Real - attr_reader :current_user - attr_reader :current_user_id - attr_reader :current_tenant - attr_reader :unscoped_token - attr_accessor :auth_token - include Fog::Identity::OpenStack::Common - include Fog::OpenStack::Core def initialize(options={}) initialize_identity options - @openstack_service_type = options[:openstack_service_type] || ['identity_v3','identityv3','identity'] - @openstack_service_name = options[:openstack_service_name] + @openstack_service_type = options[:openstack_service_type] || ['identity_v3','identityv3','identity'] + @openstack_service_name = options[:openstack_service_name] - @connection_options = options[:connection_options] || {} + @connection_options = options[:connection_options] || {} - @openstack_current_user_id = options[:openstack_current_user_id] - - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' + @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' authenticate @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - - def reload - @connection.reset - end - - def request(params) - retried = false - begin - response = @connection.request(params.merge({ - :headers => params.fetch(:headers,{}).merge({ - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - 'X-Auth-Token' => @auth_token - }), - :path => "#{@path}/#{params[:path]}" - })) - rescue Excon::Errors::Unauthorized => error - raise if retried - retried = true - - @openstack_must_reauthenticate = true - authenticate - retry - rescue Excon::Errors::HTTPStatusError => error - raise case error - when Excon::Errors::NotFound - Fog::Identity::OpenStack::NotFound.slurp(error) - else - error - end - end - unless response.body.empty? - response.body = Fog::JSON.decode(response.body) - end - response - end - end - end end end diff --git a/lib/fog/openstack/image.rb b/lib/fog/openstack/image.rb index 5457c87c6..d9824dc92 100644 --- a/lib/fog/openstack/image.rb +++ b/lib/fog/openstack/image.rb @@ -6,10 +6,15 @@ module Fog SUPPORTED_VERSIONS = /v1(\.(0|1))*/ requires :openstack_auth_url - recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_type, :openstack_service_name, :openstack_tenant, - :openstack_api_key, :openstack_username, - :current_user, :current_tenant, :openstack_endpoint_type, :openstack_region + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, + :current_user, :current_tenant, :openstack_region, + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id model_path 'fog/openstack/models/image' @@ -89,55 +94,30 @@ module Fog end class Real - attr_reader :current_user - attr_reader :current_tenant + include Fog::OpenStack::Core def initialize(options={}) - @openstack_auth_token = options[:openstack_auth_token] + initialize_identity options - unless @openstack_auth_token - missing_credentials = Array.new - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] + @openstack_service_type = options[:openstack_service_type] || ['image'] + @openstack_service_name = options[:openstack_service_name] + @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - missing_credentials << :openstack_api_key unless @openstack_api_key - missing_credentials << :openstack_username unless @openstack_username - raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? - end - - @openstack_tenant = options[:openstack_tenant] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) - @openstack_management_url = options[:openstack_management_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['image'] - @openstack_service_name = options[:openstack_service_name] - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - @openstack_region = options[:openstack_region] - - @connection_options = options[:connection_options] || {} - - @current_user = options[:current_user] - @current_tenant = options[:current_tenant] + @connection_options = options[:connection_options] || {} authenticate + unless @path.match(SUPPORTED_VERSIONS) + @path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS, + @openstack_management_uri, + @auth_token, + @connection_options) + end + @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def credentials - { :provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :current_user => @current_user, - :current_tenant => @current_tenant } - end - - def reload - @connection.reset - end - def request(params) begin response = @connection.request(params.merge({ @@ -171,47 +151,6 @@ module Fog private - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_tenant => @openstack_tenant, - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_auth_uri => @openstack_auth_uri, - :openstack_region => @openstack_region, - :openstack_auth_token => @openstack_must_reauthenticate ? nil : @openstack_auth_token, - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_endpoint_type => @openstack_endpoint_type - } - - credentials = Fog::OpenStack.authenticate(options, @connection_options) - - @current_user = credentials[:user] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @openstack_management_url = credentials[:server_management_url] - uri = URI.parse(@openstack_management_url) - else - @auth_token = @openstack_auth_token - uri = URI.parse(@openstack_management_url) - end - - @host = uri.host - @path = uri.path - @path.sub!(/\/$/, '') - unless @path.match(SUPPORTED_VERSIONS) - @path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS, - uri, - @auth_token, - @connection_options) - end - @port = uri.port - @scheme = uri.scheme - true - end end end end diff --git a/lib/fog/openstack/metering.rb b/lib/fog/openstack/metering.rb index 7007b3402..ed226d490 100644 --- a/lib/fog/openstack/metering.rb +++ b/lib/fog/openstack/metering.rb @@ -4,11 +4,15 @@ module Fog module Metering class OpenStack < Fog::Service requires :openstack_auth_url - recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_type, :openstack_service_name, :openstack_tenant, - :openstack_api_key, :openstack_username, - :current_user, :current_tenant, - :openstack_endpoint_type + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, + :current_user, :current_tenant, :openstack_region, + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id model_path 'fog/openstack/models/metering' @@ -81,34 +85,16 @@ module Fog end class Real - attr_reader :current_user - attr_reader :current_tenant + include Fog::OpenStack::Core def initialize(options={}) - @openstack_auth_token = options[:openstack_auth_token] + initialize_identity options - unless @openstack_auth_token - missing_credentials = Array.new - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] + @openstack_service_type = options[:openstack_service_type] || ['metering'] + @openstack_service_name = options[:openstack_service_name] + @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - missing_credentials << :openstack_api_key unless @openstack_api_key - missing_credentials << :openstack_username unless @openstack_username - raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? - end - - @openstack_tenant = options[:openstack_tenant] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) - @openstack_management_url = options[:openstack_management_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['metering'] - @openstack_service_name = options[:openstack_service_name] - - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - @connection_options = options[:connection_options] || {} - - @current_user = options[:current_user] - @current_tenant = options[:current_tenant] + @connection_options = options[:connection_options] || {} authenticate @@ -116,19 +102,6 @@ module Fog @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def credentials - { :provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :current_user => @current_user, - :current_tenant => @current_tenant } - end - - def reload - @connection.reset - end - def request(params) begin response = @connection.request(params.merge({ @@ -165,40 +138,6 @@ module Fog private - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_tenant => @openstack_tenant, - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_auth_uri => @openstack_auth_uri, - :openstack_auth_token => @openstack_must_reauthenticate ? nil : @openstack_auth_token, - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_endpoint_type => @openstack_endpoint_type - } - - credentials = Fog::OpenStack.authenticate(options, @connection_options) - - @current_user = credentials[:user] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @openstack_management_url = credentials[:server_management_url] - uri = URI.parse(@openstack_management_url) - else - @auth_token = @openstack_auth_token - uri = URI.parse(@openstack_management_url) - end - - @host = uri.host - @path = uri.path - @path.sub!(/\/$/, '') - @port = uri.port - @scheme = uri.scheme - true - end end end end diff --git a/lib/fog/openstack/models/orchestration/events.rb b/lib/fog/openstack/models/orchestration/events.rb index e8405f05c..e6eb3d10e 100644 --- a/lib/fog/openstack/models/orchestration/events.rb +++ b/lib/fog/openstack/models/orchestration/events.rb @@ -1,3 +1,4 @@ +require 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/event' module Fog diff --git a/lib/fog/openstack/models/orchestration/resources.rb b/lib/fog/openstack/models/orchestration/resources.rb index 19cd9ecf1..94499150d 100644 --- a/lib/fog/openstack/models/orchestration/resources.rb +++ b/lib/fog/openstack/models/orchestration/resources.rb @@ -1,3 +1,4 @@ +require 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/resource' module Fog diff --git a/lib/fog/openstack/models/orchestration/stacks.rb b/lib/fog/openstack/models/orchestration/stacks.rb index f905032b8..51bcfd284 100644 --- a/lib/fog/openstack/models/orchestration/stacks.rb +++ b/lib/fog/openstack/models/orchestration/stacks.rb @@ -1,3 +1,4 @@ +require 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/stack' module Fog diff --git a/lib/fog/openstack/models/orchestration/templates.rb b/lib/fog/openstack/models/orchestration/templates.rb index 25dda4260..d76e88b43 100644 --- a/lib/fog/openstack/models/orchestration/templates.rb +++ b/lib/fog/openstack/models/orchestration/templates.rb @@ -1,3 +1,4 @@ +require 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/template' module Fog diff --git a/lib/fog/openstack/network.rb b/lib/fog/openstack/network.rb index 5091a213e..a246ec4a2 100644 --- a/lib/fog/openstack/network.rb +++ b/lib/fog/openstack/network.rb @@ -6,13 +6,15 @@ module Fog SUPPORTED_VERSIONS = /v2(\.0)*/ requires :openstack_auth_url - recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_type, :openstack_service_name, :openstack_tenant, - :openstack_tenant_id, - :openstack_api_key, :openstack_username, :openstack_endpoint_type, + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, - :openstack_project_name, - :openstack_project_domain, :openstack_user_domain + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id ## MODELS # @@ -228,13 +230,12 @@ module Fog include Fog::OpenStack::Core def initialize(options={}) - initialize_identity options - @openstack_service_type = options[:openstack_service_type] || ['network'] - @openstack_service_name = options[:openstack_service_name] + @openstack_service_type = options[:openstack_service_type] || ['network'] + @openstack_service_name = options[:openstack_service_name] - @connection_options = options[:connection_options] || {} + @connection_options = options[:connection_options] || {} authenticate @@ -250,9 +251,6 @@ module Fog @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def reload - @connection.reset - end def request(params) begin diff --git a/lib/fog/openstack/orchestration.rb b/lib/fog/openstack/orchestration.rb index 33745cfec..8142d76ea 100644 --- a/lib/fog/openstack/orchestration.rb +++ b/lib/fog/openstack/orchestration.rb @@ -6,10 +6,13 @@ module Fog requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, - :openstack_tenant, + :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, - :openstack_endpoint_type + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id model_path 'fog/openstack/models/orchestration' model :stack @@ -124,40 +127,17 @@ module Fog end class Real - attr_reader :auth_token - attr_reader :auth_token_expiration - attr_reader :current_user - attr_reader :current_tenant + include Fog::OpenStack::Core def initialize(options={}) - @openstack_auth_token = options[:openstack_auth_token] - @auth_token = options[:openstack_auth_token] - @openstack_identity_public_endpoint = options[:openstack_identity_endpoint] + initialize_identity options - unless @auth_token - missing_credentials = Array.new - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] - - missing_credentials << :openstack_api_key unless @openstack_api_key - missing_credentials << :openstack_username unless @openstack_username - raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? - end - - @openstack_tenant = options[:openstack_tenant] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) - @openstack_management_url = options[:openstack_management_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['orchestration'] - @openstack_service_name = options[:openstack_service_name] @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity' - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL' - @openstack_region = options[:openstack_region] - @connection_options = options[:connection_options] || {} + @openstack_service_type = options[:openstack_service_type] || ['orchestration'] + @openstack_service_name = options[:openstack_service_name] - @current_user = options[:current_user] - @current_tenant = options[:current_tenant] + @connection_options = options[:connection_options] || {} authenticate @@ -165,21 +145,6 @@ module Fog @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def credentials - { :provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :openstack_identity_endpoint => @openstack_identity_public_endpoint, - :openstack_region => @openstack_region, - :current_user => @current_user, - :current_tenant => @current_tenant } - end - - def reload - @connection.reset - end - def request(params) begin response = @connection.request(params.merge({ @@ -190,7 +155,7 @@ module Fog 'X-Auth-User' => @openstack_username, 'X-Auth-Key' => @openstack_api_key }.merge!(params[:headers] || {}), - :path => "#{@path}/#{@tenant_id}/#{params[:path]}", + :path => "#{@path}/#{params[:path]}", :query => params[:query] })) rescue Excon::Errors::Unauthorized => error @@ -219,51 +184,6 @@ module Fog private - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_auth_token => @openstack_must_reauthenticate ? nil : @auth_token, - :openstack_auth_uri => @openstack_auth_uri, - :openstack_region => @openstack_region, - :openstack_tenant => @openstack_tenant, - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_identity_service_type => @openstack_identity_service_type, - :openstack_endpoint_type => @openstack_endpoint_type - } - - credentials = Fog::OpenStack.authenticate(options, @connection_options) - - @current_user = credentials[:user] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @auth_token_expiration = credentials[:expires] - @openstack_management_url = credentials[:server_management_url] - @openstack_identity_public_endpoint = credentials[:identity_public_endpoint] - end - - uri = URI.parse(@openstack_management_url) - @host = uri.host - @path, @tenant_id = uri.path.scan(/(\/.*)\/(.*)/).flatten - - @path.sub!(/\/$/, '') - - @port = uri.port - @scheme = uri.scheme - - # Not all implementations have identity service in the catalog - if @openstack_identity_public_endpoint || @openstack_management_url - @identity_connection = Fog::Core::Connection.new( - @openstack_identity_public_endpoint || @openstack_management_url, - false, @connection_options) - end - - true - end end end end diff --git a/lib/fog/openstack/planning.rb b/lib/fog/openstack/planning.rb index f2a716a92..63c5eb630 100644 --- a/lib/fog/openstack/planning.rb +++ b/lib/fog/openstack/planning.rb @@ -6,10 +6,15 @@ module Fog SUPPORTED_VERSIONS = /v2/ requires :openstack_auth_url - recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_type, :openstack_service_name, :openstack_tenant, - :openstack_api_key, :openstack_username, - :current_user, :current_tenant, :openstack_endpoint_type, :openstack_region + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, + :current_user, :current_tenant, :openstack_region, + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id ## MODELS # @@ -89,55 +94,27 @@ module Fog end class Real - attr_reader :current_user - attr_reader :current_tenant + include Fog::OpenStack::Core def initialize(options={}) - @openstack_auth_token = options[:openstack_auth_token] + initialize_identity options - unless @openstack_auth_token - missing_credentials = Array.new - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] + @openstack_service_type = options[:openstack_service_type] || ['management'] # currently Tuskar is configured as 'management' service in Keystone + @openstack_service_name = options[:openstack_service_name] + @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - missing_credentials << :openstack_api_key unless @openstack_api_key - missing_credentials << :openstack_username unless @openstack_username - raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? - end - - @openstack_tenant = options[:openstack_tenant] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) - @openstack_management_url = options[:openstack_management_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['management'] # currently Tuskar is configured as 'management' service in Keystone - @openstack_service_name = options[:openstack_service_name] - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - @openstack_region = options[:openstack_region] - - @connection_options = options[:connection_options] || {} - - @current_user = options[:current_user] - @current_tenant = options[:current_tenant] + @connection_options = options[:connection_options] || {} authenticate + unless @path.match(SUPPORTED_VERSIONS) + @path = "/v2" + end + @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def credentials - { :provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :current_user => @current_user, - :current_tenant => @current_tenant } - end - - def reload - @connection.reset - end - def request(params) begin response = @connection.request(params.merge({ @@ -171,44 +148,6 @@ module Fog private - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_tenant => @openstack_tenant, - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_auth_uri => @openstack_auth_uri, - :openstack_region => @openstack_region, - :openstack_auth_token => @openstack_must_reauthenticate ? nil : @openstack_auth_token, - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_endpoint_type => @openstack_endpoint_type - } - - credentials = Fog::OpenStack.authenticate(options, @connection_options) - - @current_user = credentials[:user] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @openstack_management_url = credentials[:server_management_url] - uri = URI.parse(@openstack_management_url) - else - @auth_token = @openstack_auth_token - uri = URI.parse(@openstack_management_url) - end - - @host = uri.host - @path = uri.path - @path.sub!(/\/$/, '') - unless @path.match(SUPPORTED_VERSIONS) - @path = "/v2" - end - @port = uri.port - @scheme = uri.scheme - true - end end end @@ -232,4 +171,3 @@ module Fog end end end - diff --git a/lib/fog/openstack/storage.rb b/lib/fog/openstack/storage.rb index 8edbcef8d..4749b78c7 100644 --- a/lib/fog/openstack/storage.rb +++ b/lib/fog/openstack/storage.rb @@ -5,11 +5,15 @@ module Fog class OpenStack < Fog::Service requires :openstack_auth_url, :openstack_username, :openstack_api_key - recognizes :persistent, :openstack_service_name, - :openstack_service_type, :openstack_tenant, - :openstack_region, :openstack_temp_url_key, - :openstack_endpoint_type, :openstack_auth_token, - :openstack_management_url + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, + :current_user, :current_tenant, :openstack_region, + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id model_path 'fog/openstack/models/storage' model :directory @@ -76,30 +80,21 @@ module Fog end class Real + include Fog::OpenStack::Core + def initialize(options={}) - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] - @openstack_auth_url = options[:openstack_auth_url] - @openstack_auth_token = options[:openstack_auth_token] - @openstack_storage_url = options[:openstack_storage_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['object-store'] - @openstack_service_name = options[:openstack_service_name] - @openstack_region = options[:openstack_region] - @openstack_tenant = options[:openstack_tenant] - @connection_options = options[:connection_options] || {} - @openstack_temp_url_key = options[:openstack_temp_url_key] - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL' - @openstack_management_url = options[:openstack_management_url] + initialize_identity options + + @openstack_service_type = options[:openstack_service_type] || ['object-store'] + @openstack_service_name = options[:openstack_service_name] + + @connection_options = options[:connection_options] || {} + authenticate @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def reload - @connection.reset - end - # Change the current account while re-using the auth token. # # This is usefull when you have an admin role and you're able @@ -180,40 +175,6 @@ module Fog private - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_auth_uri => URI.parse(@openstack_auth_url), - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_region => @openstack_region, - :openstack_tenant => @openstack_tenant, - :openstack_endpoint_type => @openstack_endpoint_type - } - - credentials = Fog::OpenStack.authenticate(options, @connection_options) - - @current_user = credentials[:user] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @openstack_management_url = credentials[:server_management_url] - uri = URI.parse(@openstack_management_url) - else - @auth_token = @openstack_auth_token - uri = URI.parse(@openstack_management_url) - end - - @host = uri.host - @path = uri.path - @path.sub!(/\/$/, '') - @port = uri.port - @scheme = uri.scheme - true - end end end end diff --git a/lib/fog/openstack/volume.rb b/lib/fog/openstack/volume.rb index af3aa53af..aa7214ab2 100644 --- a/lib/fog/openstack/volume.rb +++ b/lib/fog/openstack/volume.rb @@ -4,11 +4,15 @@ module Fog module Volume class OpenStack < Fog::Service requires :openstack_auth_url - recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_type, :openstack_service_name, :openstack_tenant, - :openstack_api_key, :openstack_username, - :current_user, :current_tenant, - :openstack_endpoint_type, :openstack_region + recognizes :openstack_auth_token, :openstack_management_url, + :persistent, :openstack_service_type, :openstack_service_name, + :openstack_tenant, :openstack_tenant_id, + :openstack_api_key, :openstack_username, :openstack_identity_endpoint, + :current_user, :current_tenant, :openstack_region, + :openstack_endpoint_type, + :openstack_project_name, :openstack_project_id, + :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, + :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id model_path 'fog/openstack/models/volume' @@ -119,55 +123,23 @@ module Fog end class Real - attr_reader :current_user - attr_reader :current_tenant + include Fog::OpenStack::Core def initialize(options={}) - @openstack_auth_token = options[:openstack_auth_token] + initialize_identity options - unless @openstack_auth_token - missing_credentials = Array.new - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] + @openstack_service_type = options[:openstack_service_type] || ['volume'] + @openstack_service_name = options[:openstack_service_name] + @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - missing_credentials << :openstack_api_key unless @openstack_api_key - missing_credentials << :openstack_username unless @openstack_username - raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? - end - - @openstack_tenant = options[:openstack_tenant] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) - @openstack_management_url = options[:openstack_management_url] - @openstack_must_reauthenticate = false - @openstack_service_type = options[:openstack_service_type] || ['volume'] - @openstack_service_name = options[:openstack_service_name] - @openstack_region = options[:openstack_region] - - @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' - @connection_options = options[:connection_options] || {} - - @current_user = options[:current_user] - @current_tenant = options[:current_tenant] + @connection_options = options[:connection_options] || {} authenticate - @persistent = options[:persistent] || false + @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end - def credentials - { :provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :current_user => @current_user, - :current_tenant => @current_tenant } - end - - def reload - @connection.reset - end - def request(params) begin response = @connection.request(params.merge({ @@ -202,41 +174,6 @@ module Fog private - def authenticate - if !@openstack_management_url || @openstack_must_reauthenticate - options = { - :openstack_region => @openstack_region, - :openstack_tenant => @openstack_tenant, - :openstack_api_key => @openstack_api_key, - :openstack_username => @openstack_username, - :openstack_auth_uri => @openstack_auth_uri, - :openstack_auth_token => @openstack_must_reauthenticate ? nil : @openstack_auth_token, - :openstack_service_type => @openstack_service_type, - :openstack_service_name => @openstack_service_name, - :openstack_endpoint_type => @openstack_endpoint_type - } - - credentials = Fog::OpenStack.authenticate(options, @connection_options) - - @current_user = credentials[:user] - @current_tenant = credentials[:tenant] - - @openstack_must_reauthenticate = false - @auth_token = credentials[:token] - @openstack_management_url = credentials[:server_management_url] - uri = URI.parse(@openstack_management_url) - else - @auth_token = @openstack_auth_token - uri = URI.parse(@openstack_management_url) - end - - @host = uri.host - @path = uri.path - @path.sub!(/\/$/, '') - @port = uri.port - @scheme = uri.scheme - true - end end end end