Hi, My patch was lost somehow ;-) So I resending it using Forward.
-- Michal -- -------------------------------------------------------- Michal Fojtik, [email protected] Deltacloud API: http://deltacloud.org --------------------------------------------------------
--- Begin Message ------ src/app/models/hardware_profile.rb | 2 ++ src/app/models/provider.rb | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb index 2ce6d81..91fa9fc 100644 --- a/src/app/models/hardware_profile.rb +++ b/src/app/models/hardware_profile.rb @@ -21,8 +21,10 @@ class HardwareProfile < ActiveRecord::Base has_many :instances + named_scope :frontend, :conditions => { :provider_id => nil } has_many :provider_instances, :class_name => "Instance", :foreign_key => "provider_hardware_profile_id" + belongs_to :provider belongs_to :memory, :class_name => "HardwareProfileProperty", diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index ed8fc70..0fec5ca 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -81,16 +81,24 @@ class Provider < ActiveRecord::Base :provider_id => id) ar_hardware_profile.add_properties(hardware_profile) ar_hardware_profile.save! - front_hwp = HardwareProfile.new(:external_key => - name + - Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER + - ar_hardware_profile.external_key, - :name => name + - Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER + - ar_hardware_profile.name) - front_hwp.add_properties(hardware_profile) - front_hwp.provider_hardware_profiles << ar_hardware_profile - front_hwp.save! + + front_hwp = HardwareProfile.new(:external_key =>ar_hardware_profile.external_key, + :name => ar_hardware_profile.name) + + # Omit creation of new front-end hardware profile if + # hardware profile with same external_key exists + + avail_hwp = HardwareProfile.frontend.find(:all, :conditions => { :external_key => front_hwp.external_key }) + + if avail_hwp.empty? + front_hwp.add_properties(hardware_profile) + front_hwp.provider_hardware_profiles << ar_hardware_profile + front_hwp.save! + else + avail_hwp.each do |hwp| + hwp.provider_hardware_profiles << ar_hardware_profile + end + end end end end -- 1.7.2.2
--- End Message ---
_______________________________________________ deltacloud-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/deltacloud-devel
