diff --git a/lib/fog/core/errors.rb b/lib/fog/core/errors.rb index 2d76c8788..6066dffce 100644 --- a/lib/fog/core/errors.rb +++ b/lib/fog/core/errors.rb @@ -45,6 +45,7 @@ An alternate file may be used by placing its path in the FOG_RC environment vari :hp_account_id: :hp_secret_key: :hp_tenant_id: + :hp_avl_zone: :linode_api_key: :local_root: :new_servers_password: diff --git a/lib/fog/hp.rb b/lib/fog/hp.rb index a5720ac11..f232d6931 100644 --- a/lib/fog/hp.rb +++ b/lib/fog/hp.rb @@ -107,7 +107,7 @@ module Fog @hp_secret_key = options[:hp_secret_key] @hp_tenant_id = options[:hp_tenant_id] @hp_service_type = options[:hp_service_type] - @hp_avl_zone = options[:hp_avl_zone] || :az1 + @hp_avl_zone = options[:hp_avl_zone] ### Decide which auth style to use unless (@hp_use_upass_auth_style) @@ -177,19 +177,19 @@ module Fog private def self.get_endpoint_from_catalog(service_catalog, service_type, avl_zone) - if service_catalog - service_item = service_catalog.select {|s| s["type"] == service_type}.first - if service_item and service_item['endpoints'] and - if avl_zone == :az1 - endpoint_url = service_item['endpoints'][0]['publicURL'] if service_item['endpoints'][0] - elsif avl_zone == :az2 - endpoint_url = service_item['endpoints'][1]['publicURL'] if service_item['endpoints'][1] - end - raise "Unable to retrieve endpoint service url from service catalog." if endpoint_url.nil? - return endpoint_url + raise "Unable to parse service catalog." unless service_catalog + service_item = service_catalog.detect do |s| + s["type"] == service_type + end + if service_item and service_item['endpoints'] + endpoint = service_item['endpoints'].detect do |ep| + ep['region'] == avl_zone end + endpoint_url = endpoint['publicURL'] if endpoint + raise "Unable to retrieve endpoint service url for availability zone '#{avl_zone}' from service catalog. " if endpoint_url.nil? + return endpoint_url else - raise "Unable to parse service catalog." + raise "Unable to retrieve service item for '#{service_type}' from service catalog." end end diff --git a/lib/fog/hp/compute.rb b/lib/fog/hp/compute.rb index cbe9eb866..1ebb51455 100644 --- a/lib/fog/hp/compute.rb +++ b/lib/fog/hp/compute.rb @@ -5,8 +5,8 @@ module Fog module Compute class HP < Fog::Service - requires :hp_secret_key, :hp_account_id, :hp_tenant_id - recognizes :hp_auth_uri, :hp_servicenet, :persistent, :connection_options, :hp_use_upass_auth_style, :hp_auth_version, :hp_avl_zone + requires :hp_secret_key, :hp_account_id, :hp_tenant_id, :hp_avl_zone + recognizes :hp_auth_uri, :hp_servicenet, :persistent, :connection_options, :hp_use_upass_auth_style, :hp_auth_version model_path 'fog/hp/models/compute' model :address diff --git a/tests/helpers/mock_helper.rb b/tests/helpers/mock_helper.rb index 9356de4f1..63a468c8d 100644 --- a/tests/helpers/mock_helper.rb +++ b/tests/helpers/mock_helper.rb @@ -31,6 +31,7 @@ if Fog.mock? :hp_account_id => 'hp_account_id', :hp_secret_key => 'hp_secret_key', :hp_tenant_id => 'hp_tenant_id', + :hp_avl_zone => 'hp_avl_zone', :linode_api_key => 'linode_api_key', :local_root => '~/.fog', :new_servers_password => 'new_servers_password', diff --git a/tests/hp/models/compute/address_tests.rb b/tests/hp/models/compute/address_tests.rb index 8add29942..137ae7463 100644 --- a/tests/hp/models/compute/address_tests.rb +++ b/tests/hp/models/compute/address_tests.rb @@ -1,6 +1,6 @@ Shindo.tests("Fog::Compute[:hp] | address", ['hp']) do - @base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242 + @base_image_id = ENV["BASE_IMAGE_ID"] || 1242 model_tests(Fog::Compute[:hp].addresses, {}, true) do diff --git a/tests/hp/requests/compute/address_tests.rb b/tests/hp/requests/compute/address_tests.rb index 2a4970f8c..078895a9d 100644 --- a/tests/hp/requests/compute/address_tests.rb +++ b/tests/hp/requests/compute/address_tests.rb @@ -7,7 +7,7 @@ Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do 'id' => Integer } - @base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242 + @base_image_id = ENV["BASE_IMAGE_ID"] || 1242 tests('success') do diff --git a/tests/hp/requests/compute/image_tests.rb b/tests/hp/requests/compute/image_tests.rb index cbce0179e..f325c97b9 100644 --- a/tests/hp/requests/compute/image_tests.rb +++ b/tests/hp/requests/compute/image_tests.rb @@ -18,7 +18,7 @@ Shindo.tests('Fog::Compute[:hp] | image requests', ['hp']) do 'name' => String } - @base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242 + @base_image_id = ENV["BASE_IMAGE_ID"] || 1242 tests('success') do @server_name = "fogservertest" diff --git a/tests/hp/requests/compute/server_address_tests.rb b/tests/hp/requests/compute/server_address_tests.rb index 89478c202..6f596fffa 100644 --- a/tests/hp/requests/compute/server_address_tests.rb +++ b/tests/hp/requests/compute/server_address_tests.rb @@ -1,6 +1,6 @@ Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do - @base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242 + @base_image_id = ENV["BASE_IMAGE_ID"] || 1242 tests('success') do @server = Fog::Compute[:hp].servers.create(:name => 'fogaddresstests', :flavor_id => 100, :image_id => @base_image_id) diff --git a/tests/hp/requests/compute/server_tests.rb b/tests/hp/requests/compute/server_tests.rb index f9c064a00..36858286a 100644 --- a/tests/hp/requests/compute/server_tests.rb +++ b/tests/hp/requests/compute/server_tests.rb @@ -34,7 +34,7 @@ Shindo.tests('Fog::Compute[:hp] | server requests', ['hp']) do 'output' => String } - @base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242 + @base_image_id = ENV["BASE_IMAGE_ID"] || 1242 tests('success') do