Set backend status when saving backend version of object
[plstackapi.git] / planetstack / openstack_observer / steps / sync_controller_images.py
index 4446d9a..fa0cad1 100644 (file)
@@ -7,6 +7,7 @@ from observer.openstacksyncstep import OpenStackSyncStep
 from core.models import Controller
 from core.models import Image, ControllerImages
 from util.logger import Logger, logging
+from observer.ansible import *
 \r
 logger = Logger(level=logging.INFO)
 
@@ -23,19 +24,18 @@ class SyncControllerImages(OpenStackSyncStep):
 
     def sync_record(self, controller_image):
         logger.info("Working on image %s on controller %s" % (controller_image.image.name, controller_image.controller))
+        image_fields = {'endpoint':controller_image.controller.auth_url,
+                        'admin_user':controller_image.controller.admin_user,
+                        'admin_password':controller_image.controller.admin_password,
+                        'name':controller_image.image.name,
+                        'filepath':controller_image.image.path,
+                        'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
+                        }
 
-       image_fields = {'endpoint':controller_image.controller.auth_url,
-                       'admin_user':controller_image.controller.admin_user,
-                       'admin_password':controller_image.controller.admin_password,
-                       'name':controller_image.image.name,
-                       'filepath':controller_image.image.path
-                       }
 
-       res = run_template('sync_controller_images.yaml', image_fields)
+        res = run_template('sync_controller_images.yaml', image_fields, path='controller_images', expected_num=1)
 
-       if (len(res)!=1):
-           raise Exception('Could not sync image %s'%controller_image.image.name)
-       else:
-           image_id = res[0]['id'] 
-            controller_image.glance_image_id = image_id
-            controller_image.save()
+        image_id = res[0]['id']
+        controller_image.glance_image_id = image_id
+       controller_image.backend_status = '1 - OK'
+        controller_image.save()