Fix for https://www.aeolusproject.org/redmine/issues/1510
This should work and shouldn't break any new tests, but I didn't test it on providers that actually get affected by this as I don't have access to them.
Ian, please take a look at it and let me know if it solves the problem.
From: Tomas Sedovic tsedovic@redhat.com
This fixes https://www.aeolusproject.org/redmine/issues/1510
Some providers require authentication in order to access hardware profiles via their API.
Previously, we were loading HWPs when a provider was added to Conductor. Now, they're loaded when a provider account is added to the provider -- much like it's been with realms. --- .../controllers/provider_accounts_controller.rb | 2 +- src/app/controllers/providers_controller.rb | 2 +- src/app/models/provider.rb | 16 ---------------- src/app/models/provider_account.rb | 18 ++++++++++++++++++ 4 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/src/app/controllers/provider_accounts_controller.rb b/src/app/controllers/provider_accounts_controller.rb index 9ae24c9..9a74889 100644 --- a/src/app/controllers/provider_accounts_controller.rb +++ b/src/app/controllers/provider_accounts_controller.rb @@ -68,7 +68,7 @@ class ProviderAccountsController < ApplicationController @provider_account.pool_families << PoolFamily.default @provider_account.save! @provider_account.assign_owner_roles(current_user) - if @provider_account.populate_realms + if @provider_account.populate_realms and @provider_account.populate_hardware_profiles flash[:notice] = "Provider account added." end redirect_to provider_account_path(@provider_account) diff --git a/src/app/controllers/providers_controller.rb b/src/app/controllers/providers_controller.rb index 2278896..623e31b 100644 --- a/src/app/controllers/providers_controller.rb +++ b/src/app/controllers/providers_controller.rb @@ -64,7 +64,7 @@ class ProvidersController < ApplicationController flash[:notice] = "Failed to connect to Provider" render :action => "new" else - if @provider.save && @provider.populate_hardware_profiles + if @provider.save @provider.assign_owner_roles(current_user) flash[:notice] = "Provider added." redirect_to providers_path diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index fa42beb..3263c6a 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -91,22 +91,6 @@ class Provider < ActiveRecord::Base end end
- def populate_hardware_profiles - # FIXME: once API has hw profiles, change the below - hardware_profiles = connect.hardware_profiles - # FIXME: this should probably be in the same transaction as provider.save - self.transaction do - hardware_profiles.each do |hardware_profile| - ar_hardware_profile = HardwareProfile.new(:external_key => - hardware_profile.id, - :name => hardware_profile.id, - :provider_id => id) - ar_hardware_profile.add_properties(hardware_profile) - ar_hardware_profile.save! - end - end - end - def pools cloud_accounts.collect {|account| account.pools}.flatten.uniq end diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb index b1c1bb8..cf58e14 100644 --- a/src/app/models/provider_account.rb +++ b/src/app/models/provider_account.rb @@ -162,6 +162,24 @@ class ProviderAccount < ActiveRecord::Base end end
+ def populate_hardware_profiles + # FIXME: once API has hw profiles, change the below + hardware_profiles = connect.hardware_profiles + self.transaction do + hardware_profiles.each do |hardware_profile| + unless HardwareProfile.find_by_external_key_and_provider_id(hardware_profile.id, + provider.id) + ar_hardware_profile = HardwareProfile.new(:external_key => + hardware_profile.id, + :name => hardware_profile.id, + :provider_id => provider.id) + ar_hardware_profile.add_properties(hardware_profile) + ar_hardware_profile.save! + end + end + end + end + def valid_credentials? if credentials_hash['username'].blank? || credentials_hash['password'].blank? return false
On Mon, May 23, 2011 at 03:30:02PM +0200, tsedovic@redhat.com wrote:
From: Tomas Sedovic tsedovic@redhat.com
This fixes https://www.aeolusproject.org/redmine/issues/1510
Some providers require authentication in order to access hardware profiles via their API.
Previously, we were loading HWPs when a provider was added to Conductor. Now, they're loaded when a provider account is added to the provider -- much like it's been with realms.
Thanks!
ACK
Ian
aeolus-devel@lists.fedorahosted.org