When an image build is requested, an entry is placed in the db for
a replicated image.  However it is not yet ready for use but we were
generating classads for them anyway.  This change makes it so we do
not generate classads unless an image key is present and they are
ready to be used.

Signed-off-by: Ian Main <[email protected]>
---
 src/app/util/condormatic.rb |   60 +++++++++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/src/app/util/condormatic.rb b/src/app/util/condormatic.rb
index dcf74ef..b1faaab 100644
--- a/src/app/util/condormatic.rb
+++ b/src/app/util/condormatic.rb
@@ -242,33 +242,39 @@ def condormatic_classads_sync
   providers.each do |provider|
     provider.cloud_accounts.each do |account|
       provider.replicated_images.each do |replicated_image|
-        provider.hardware_profiles.each do |hwp|
-          provider.realms.each do |realm|
-            pipe = IO.popen("condor_advertise UPDATE_STARTD_AD 2>&1", "w+")
-
-            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.aggregator_hardware_profiles[0].id}\""
-            pipe.puts "image=\"#{replicated_image.image.template.id}\""
-            pipe.puts "realm=\"#{realm.frontend_realms[0].id}\""
-            pipe.puts "\n# Backend info to complete this job:"
-            pipe.puts "image_key=\"#{replicated_image.provider_image_key}\""
-            pipe.puts "hardwareprofile_key=\"#{hwp.external_key}\""
-            pipe.puts "realm_key=\"#{realm.external_key}\""
-            pipe.puts "provider_url=\"#{account.provider.url}\""
-            pipe.puts "username=\"#{account.username}\""
-            pipe.puts "password=\"#{account.password}\""
-            pipe.puts "cloud_account_id=\"#{account.id}\""
-            pipe.close_write
-
-            out = pipe.read
-            pipe.close
-
-            Rails.logger.error "Unable to submit condor classad: #{out}" if $? 
!= 0
-
-            index += 1
+        # The replicated 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
+        # it is ready to be used.  When ready it will have an image key 
assigned
+        # to it.
+        if replicated_image.provider_image_key != nil
+          provider.hardware_profiles.each do |hwp|
+            provider.realms.each do |realm|
+              pipe = IO.popen("condor_advertise UPDATE_STARTD_AD 2>&1", "w+")
+
+              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.aggregator_hardware_profiles[0].id}\""
+              pipe.puts "image=\"#{replicated_image.image.template.id}\""
+              pipe.puts "realm=\"#{realm.frontend_realms[0].id}\""
+              pipe.puts "\n# Backend info to complete this job:"
+              pipe.puts "image_key=\"#{replicated_image.provider_image_key}\""
+              pipe.puts "hardwareprofile_key=\"#{hwp.external_key}\""
+              pipe.puts "realm_key=\"#{realm.external_key}\""
+              pipe.puts "provider_url=\"#{account.provider.url}\""
+              pipe.puts "username=\"#{account.username}\""
+              pipe.puts "password=\"#{account.password}\""
+              pipe.puts "cloud_account_id=\"#{account.id}\""
+              pipe.close_write
+
+              out = pipe.read
+              pipe.close
+
+              Rails.logger.error "Unable to submit condor classad: #{out}" if 
$? != 0
+
+              index += 1
+            end
           end
         end
       end
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to