blob: c1e5136767274bc7541f50c9d20cb7b88f5a96ee [file] [log] [blame]
Scott Bakerb63ea792016-08-11 10:24:48 -07001import os
2import base64
3from collections import defaultdict
4from django.db.models import F, Q
5from xos.config import Config
6from synchronizers.base.openstacksyncstep import OpenStackSyncStep
7from synchronizers.base.syncstep import *
8from core.models import Controller
9from core.models import Image, ControllerImages
10from xos.logger import observer_logger as logger
11from synchronizers.base.ansible import *
12import json
13
14class SyncControllerImages(OpenStackSyncStep):
15 provides=[ControllerImages]
16 observes = ControllerImages
17 requested_interval=0
18 playbook='sync_controller_images.yaml'
19
20 def fetch_pending(self, deleted):
21 if (deleted):
22 return []
23
24 # now we return all images that need to be enacted
25 return ControllerImages.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
26
27 def map_sync_inputs(self, controller_image):
28 image_fields = {'endpoint':controller_image.controller.auth_url,
29 'endpoint_v3': controller_image.controller.auth_url_v3,
30 'admin_user':controller_image.controller.admin_user,
31 'admin_password':controller_image.controller.admin_password,
32 'domain': controller_image.controller.domain,
33 'name':controller_image.image.name,
34 'filepath':controller_image.image.path,
35 'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
36 }
37
38 return image_fields
39
40 def map_sync_outputs(self, controller_image, res):
41 image_id = res[0]['id']
42 controller_image.glance_image_id = image_id
43 controller_image.backend_status = '1 - OK'
44 controller_image.save()