From: Martyn Taylor mtaylor@redhat.com
--- src/app/models/hardware_profile.rb | 27 -------------------- src/app/models/provider.rb | 18 ------------- ...110302124928_remove_hardware_profile_mapping.rb | 12 +++++++++ 3 files changed, 12 insertions(+), 45 deletions(-) create mode 100644 src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb index daa66e7..75a501b 100644 --- a/src/app/models/hardware_profile.rb +++ b/src/app/models/hardware_profile.rb @@ -71,18 +71,6 @@ class HardwareProfile < ActiveRecord::Base
accepts_nested_attributes_for :memory, :cpu, :storage, :architecture
- has_and_belongs_to_many :conductor_hardware_profiles, - :class_name => "HardwareProfile", - :join_table => "hardware_profile_map", - :foreign_key => "provider_hardware_profile_id", - :association_foreign_key => "conductor_hardware_profile_id" - - has_and_belongs_to_many :provider_hardware_profiles, - :class_name => "HardwareProfile", - :join_table => "hardware_profile_map", - :foreign_key => "conductor_hardware_profile_id", - :association_foreign_key => "provider_hardware_profile_id" - validates_presence_of :external_key, :if => Proc.new { |hwp| !hwp.provider.nil? } validates_uniqueness_of :external_key, :scope => [:provider_id], :if => Proc.new { |hwp| !hwp.provider.nil? }
@@ -99,21 +87,6 @@ class HardwareProfile < ActiveRecord::Base !provider.nil? end
- # FIXME: what about custom instance profiles? - def validate - if provider.nil? - if !conductor_hardware_profiles.empty? - errors.add(:conductor_hardware_profiles, - "Conductor profiles only allowed for provider profiles") - end - else - if !provider_hardware_profiles.empty? - errors.add(:provider_hardware_profiles, - "Provider profiles only allowed for conductor profiles") - end - end - end - def add_properties(api_profile) self.memory = new_property(api_profile.memory) self.storage = new_property(api_profile.storage) diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index dfb94c3..1e6b27c 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -116,24 +116,6 @@ class Provider < ActiveRecord::Base :provider_id => id) ar_hardware_profile.add_properties(hardware_profile) ar_hardware_profile.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 diff --git a/src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb b/src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb new file mode 100644 index 0000000..61b8724 --- /dev/null +++ b/src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb @@ -0,0 +1,12 @@ +class RemoveHardwareProfileMapping < ActiveRecord::Migration + def self.up + drop_table :hardware_profile_map + end + + def self.down + create_table "hardware_profile_map", :force => true, :id => false do |t| + t.column "conductor_hardware_profile_id", :integer + t.column "provider_hardware_profile_id", :integer + end + end +end
From: Martyn Taylor mtaylor@redhat.com
--- .../admin/hardware_profiles_controller.rb | 4 + src/app/util/condormatic.rb | 79 +++++++++++--------- 2 files changed, 49 insertions(+), 34 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb b/src/app/controllers/admin/hardware_profiles_controller.rb index c56658f..a236d59 100644 --- a/src/app/controllers/admin/hardware_profiles_controller.rb +++ b/src/app/controllers/admin/hardware_profiles_controller.rb @@ -58,9 +58,11 @@ class Admin::HardwareProfilesController < ApplicationController matching_provider_hardware_profiles render :action => 'new' end + kick_condor end
def delete + kick_condor end
def edit @@ -91,10 +93,12 @@ class Admin::HardwareProfilesController < ApplicationController flash[:notice] = "Hardware Profile updated!" redirect_to admin_hardware_profiles_path end + kick_condor end
def multi_destroy HardwareProfile.destroy(params[:hardware_profile_selected]) + kick_condor redirect_to admin_hardware_profiles_path end
diff --git a/src/app/util/condormatic.rb b/src/app/util/condormatic.rb index 3f2984d..03484ff 100644 --- a/src/app/util/condormatic.rb +++ b/src/app/util/condormatic.rb @@ -47,8 +47,8 @@ def condormatic_instance_create(task) Rails.logger.error "DeltacloudPassword = $$(password)\n" pipe.puts "DeltacloudImageId = $$(image_key)\n" Rails.logger.error "DeltacloudImageId = $$(image_key)\n" - pipe.puts "DeltacloudHardwareProfile = $$(hardwareprofile_key)\n" - Rails.logger.error "DeltacloudHardwareProfile = $$(hardwareprofile_key)\n" + pipe.puts "DeltacloudHardwareProfile = $$(hardware_profile_key)\n" + Rails.logger.error "DeltacloudHardwareProfile = $$(hardware_profile_key)\n" pipe.puts "DeltacloudKeyname = $$(keypair)\n" Rails.logger.error "DeltacloudKeyname = $$(keypair)\n"
@@ -57,7 +57,7 @@ def condormatic_instance_create(task) Rails.logger.error "DeltacloudRealmId = $$(realm_key)\n" end
- requirements = "requirements = hardwareprofile == "#{instance.hardware_profile.id}" && image == "#{instance.template.id}"" + requirements = "requirements = front_end_hardware_profile_id == "#{instance.hardware_profile.id}" && image == "#{instance.template.id}"" requirements += " && realm == "#{realm.id}"" if realm != nil # Call into the deltacloud quota plugin. This uses a REST API to call back into the # conductor to check quotas as the last thing in the logical AND to match a provider @@ -208,6 +208,9 @@ def condormatic_classads_sync
Rails.logger.info "Syncing classads.." ads = [] + + front_end_hardware_profiles = HardwareProfile.find(:all, :conditions => ["provider_id IS NULL"]) + providers.each do |provider| # The provider image entry gets put in the database as soon as we ask # to have the image built, so we only want to generate classads for it if @@ -216,11 +219,11 @@ def condormatic_classads_sync provider_images = provider.provider_images.find(:all, :conditions => ['provider_image_key IS NOT NULL']) accounts = provider.provider_accounts - hardware_profiles = provider.hardware_profiles realms = provider.realms + accounts.each do |account| provider_images.each do |provider_img| - hardware_profiles.each do |hwp| + front_end_hardware_profiles.each do |hwp| # when user doesn't select any realm ads << [account, provider_img, hwp, nil, nil] # add all backend->frontend mappings @@ -240,38 +243,46 @@ def condormatic_classads_sync ads.each { |ad| account, provider_image, hwp, realm, frontend_realm = *ad
- pipe = IO.popen("condor_advertise UPDATE_STARTD_AD 2>&1", "w+") - - begin - pipe.puts "Name="provider_combination_#{index}"" - pipe.puts 'MyType="Machine"' - pipe.puts 'Requirements=true' - pipe.puts "\n# Stuff needed to match:" - pipe.puts "hardwareprofile="#{hwp.conductor_hardware_profiles[0].id}"" - pipe.puts "image="#{provider_image.image.template.id}"" - pipe.puts "realm="#{frontend_realm ? frontend_realm.id : ''}"" - pipe.puts "\n# Backend info to complete this job:" - pipe.puts "image_key="#{provider_image.provider_image_key}"" - pipe.puts "hardwareprofile_key="#{hwp.external_key}"" - pipe.puts "realm_key="#{realm ? realm.external_key : ''}"" - pipe.puts "provider_url="#{account.provider.url}"" - pipe.puts "username="#{account.username}"" - pipe.puts "password="#{account.password}"" - pipe.puts "provider_account_id="#{account.id}"" - pipe.puts "keypair="#{account.instance_key.name}"" - rescue Exception => ex - Rails.logger.error "Error writing provider classad to condor." - Rails.logger.error ex.message - Rails.logger.error ex.backtrace - end - pipe.close_write + matching_hardware_profile = HardwareProfile.match_provider_hardware_profile(account.provider, hwp) + if(matching_hardware_profile != nil) + overrides = HardwareProfile.generate_override_property_values(hwp, matching_hardware_profile) + pipe = IO.popen("condor_advertise UPDATE_STARTD_AD 2>&1", "w+") + + begin + pipe.puts "Name="provider_combination_#{index}"" + pipe.puts 'MyType="Machine"' + pipe.puts 'Requirements=true' + pipe.puts "\n# Stuff needed to match:" + pipe.puts "front_end_hardware_profile_id="#{hwp.id}"" + pipe.puts "image="#{provider_image.image.template.id}"" + pipe.puts "realm="#{frontend_realm ? frontend_realm.id : ''}"" + pipe.puts "\n# Backend info to complete this job:" + pipe.puts "image_key="#{provider_image.provider_image_key}"" + pipe.puts "hardware_profile_key="#{matching_hardware_profile.external_key}"" + pipe.puts "hardware_profile_memory="#{overrides[:memory]}"" + pipe.puts "hardware_profile_storage="#{overrides[:storage]}"" + pipe.puts "hardware_profile_cpu="#{overrides[:cpu]}"" + pipe.puts "hardware_profile_architecuture="#{overrides[:architecture]}"" + pipe.puts "realm_key="#{realm ? realm.external_key : ''}"" + pipe.puts "provider_url="#{account.provider.url}"" + pipe.puts "username="#{account.username}"" + pipe.puts "password="#{account.password}"" + pipe.puts "provider_account_id="#{account.id}"" + pipe.puts "keypair="#{account.instance_key.name}"" + rescue Exception => ex + Rails.logger.error "Error writing provider classad to condor." + Rails.logger.error ex.message + Rails.logger.error ex.backtrace + end + pipe.close_write
- out = pipe.read - pipe.close + out = pipe.read + pipe.close
- Rails.logger.error "Unable to submit condor classad: #{out}" if $? != 0 + Rails.logger.error "Unable to submit condor classad: #{out}" if $? != 0
- index += 1 + index += 1 + end } Rails.logger.info "done" end
ACK. Tests fail for the first patch, but the resent update fixes that.
On 03/02/2011 02:22 PM, mtaylor@redhat.com wrote:
From: Martyn Taylormtaylor@redhat.com
src/app/models/hardware_profile.rb | 27 -------------------- src/app/models/provider.rb | 18 ------------- ...110302124928_remove_hardware_profile_mapping.rb | 12 +++++++++ 3 files changed, 12 insertions(+), 45 deletions(-) create mode 100644 src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb index daa66e7..75a501b 100644 --- a/src/app/models/hardware_profile.rb +++ b/src/app/models/hardware_profile.rb @@ -71,18 +71,6 @@ class HardwareProfile< ActiveRecord::Base
accepts_nested_attributes_for :memory, :cpu, :storage, :architecture
- has_and_belongs_to_many :conductor_hardware_profiles,
:class_name => "HardwareProfile",
:join_table => "hardware_profile_map",
:foreign_key => "provider_hardware_profile_id",
:association_foreign_key => "conductor_hardware_profile_id"
- has_and_belongs_to_many :provider_hardware_profiles,
:class_name => "HardwareProfile",
:join_table => "hardware_profile_map",
:foreign_key => "conductor_hardware_profile_id",
:association_foreign_key => "provider_hardware_profile_id"
- validates_presence_of :external_key, :if => Proc.new { |hwp| !hwp.provider.nil? } validates_uniqueness_of :external_key, :scope => [:provider_id], :if => Proc.new { |hwp| !hwp.provider.nil? }
@@ -99,21 +87,6 @@ class HardwareProfile< ActiveRecord::Base !provider.nil? end
- # FIXME: what about custom instance profiles?
- def validate
- if provider.nil?
if !conductor_hardware_profiles.empty?
errors.add(:conductor_hardware_profiles,
"Conductor profiles only allowed for provider profiles")
end
- else
if !provider_hardware_profiles.empty?
errors.add(:provider_hardware_profiles,
"Provider profiles only allowed for conductor profiles")
end
- end
- end
- def add_properties(api_profile) self.memory = new_property(api_profile.memory) self.storage = new_property(api_profile.storage)
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index dfb94c3..1e6b27c 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -116,24 +116,6 @@ class Provider< ActiveRecord::Base :provider_id => id) ar_hardware_profile.add_properties(hardware_profile) ar_hardware_profile.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
endend end end
diff --git a/src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb b/src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb new file mode 100644 index 0000000..61b8724 --- /dev/null +++ b/src/db/migrate/20110302124928_remove_hardware_profile_mapping.rb @@ -0,0 +1,12 @@ +class RemoveHardwareProfileMapping< ActiveRecord::Migration
- def self.up
- drop_table :hardware_profile_map
- end
- def self.down
- create_table "hardware_profile_map", :force => true, :id => false do |t|
t.column "conductor_hardware_profile_id", :integer
t.column "provider_hardware_profile_id", :integer
- end
- end
+end
aeolus-devel@lists.fedorahosted.org