From c643bd8e03889d0f34f073f7225ca9812f60cbf1 Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Sun, 4 Mar 2012 15:42:20 +0800 Subject: [PATCH] [openstack] Update Reinitialization Process of Existing Auth Token --- lib/fog/openstack/compute.rb | 20 +++++++++++++++----- lib/fog/openstack/identity.rb | 21 +++++++++++++++------ lib/fog/openstack/image.rb | 21 +++++++++++++++------ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index 75c566952..3c924c7e7 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -6,9 +6,10 @@ module Fog module Compute class OpenStack < Fog::Service - requires :openstack_api_key, :openstack_username, :openstack_auth_url + requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, - :persistent, :openstack_service_name, :openstack_tenant + :persistent, :openstack_service_name, :openstack_tenant, + :openstack_api_key, :openstack_username ## MODELS # @@ -190,11 +191,20 @@ module Fog attr_reader :auth_token def initialize(options={}) - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] + @openstack_auth_token = options[:openstack_auth_token] + + 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_auth_token = options[:openstack_auth_token] @openstack_management_url = options[:openstack_management_url] @openstack_must_reauthenticate = false @openstack_service_name = options[:openstack_service_name] || ['nova', 'compute'] diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index f130c2741..209854eb1 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -5,9 +5,10 @@ module Fog module Identity class OpenStack < Fog::Service - requires :openstack_api_key, :openstack_username, :openstack_auth_url + requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_name, :openstack_tenant + :openstack_service_name, :openstack_tenant, + :openstack_api_key, :openstack_username model_path 'fog/openstack/models/identity' model :tenant @@ -49,7 +50,6 @@ module Fog request :list_roles - class Mock def self.data @data ||= Hash.new do |hash, key| @@ -84,11 +84,20 @@ module Fog def initialize(options={}) require 'multi_json' - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] + @openstack_auth_token = options[:openstack_auth_token] + + 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_auth_token = options[:openstack_auth_token] @openstack_management_url = options[:openstack_management_url] @openstack_must_reauthenticate = false @openstack_service_name = options[:openstack_service_name] || ['identity'] diff --git a/lib/fog/openstack/image.rb b/lib/fog/openstack/image.rb index 9b0d24a3f..34390576c 100644 --- a/lib/fog/openstack/image.rb +++ b/lib/fog/openstack/image.rb @@ -5,9 +5,10 @@ module Fog module Image class OpenStack < Fog::Service - requires :openstack_api_key, :openstack_username, :openstack_auth_url + requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, - :openstack_service_name, :openstack_tenant + :openstack_service_name, :openstack_tenant, + :openstack_api_key, :openstack_username model_path 'fog/openstack/models/image' @@ -29,7 +30,6 @@ module Fog request :delete_image request :get_image_by_id - class Mock def self.data @data ||= Hash.new do |hash, key| @@ -63,10 +63,19 @@ module Fog def initialize(options={}) require 'multi_json' - @openstack_api_key = options[:openstack_api_key] - @openstack_username = options[:openstack_username] - @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_auth_token = options[:openstack_auth_token] + + 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_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_management_url = options[:openstack_management_url] @openstack_must_reauthenticate = false @openstack_service_name = options[:openstack_service_name] || ['image']