blob: 17ffe57aef1dceea7eac8a26f50b543b66f0a0f0 [file] [log] [blame]
Tony Mackf3bbe472014-11-30 15:33:35 -05001import os
2import base64
3from collections import defaultdict
4from django.db.models import F, Q
5from planetstack.config import Config
6from observer.openstacksyncstep import OpenStackSyncStep
Tony Mack336e0f92014-11-30 15:53:08 -05007from core.models import Controller
8from core.models import Image, ControllerImages
Tony Mackf3bbe472014-11-30 15:33:35 -05009from util.logger import Logger, logging
Sapan Bhatiae6f4f142014-12-22 01:41:55 -050010from observer.ansible import *
Tony Mackf3bbe472014-11-30 15:33:35 -050011
12logger = Logger(level=logging.INFO)
13
Tony Mack336e0f92014-11-30 15:53:08 -050014class SyncControllerImages(OpenStackSyncStep):
Sapan Bhatia90671a82015-01-16 22:12:20 +000015 provides=[ControllerImages, Image]
Tony Mackf3bbe472014-11-30 15:33:35 -050016 requested_interval=0
17
18 def fetch_pending(self, deleted):
19 if (deleted):
20 return []
Tony Mackf3bbe472014-11-30 15:33:35 -050021
22 # now we return all images that need to be enacted
Tony Mack336e0f92014-11-30 15:53:08 -050023 return ControllerImages.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mackf3bbe472014-11-30 15:33:35 -050024
Tony Mack336e0f92014-11-30 15:53:08 -050025 def sync_record(self, controller_image):
26 logger.info("Working on image %s on controller %s" % (controller_image.image.name, controller_image.controller))
Sapan Bhatia90671a82015-01-16 22:12:20 +000027 image_fields = {'endpoint':controller_image.controller.auth_url,
28 'admin_user':controller_image.controller.admin_user,
29 'admin_password':controller_image.controller.admin_password,
30 'name':controller_image.image.name,
31 'filepath':controller_image.image.path,
32 'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
33 }
Tony Mackf3bbe472014-11-30 15:33:35 -050034
Tony Mackf3bbe472014-11-30 15:33:35 -050035
Sapan Bhatiab0464ba2015-01-23 16:21:57 +000036 res = run_template('sync_controller_images.yaml', image_fields, path='controller_images', expected_num=1)
37
38 image_id = res[0]['id']
39 controller_image.glance_image_id = image_id
40 controller_image.save()