Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from collections import defaultdict |
| 4 | from django.db.models import F, Q |
| 5 | from xos.config import Config |
Scott Baker | 8b75e85 | 2016-08-16 15:04:59 -0700 | [diff] [blame] | 6 | from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 7 | from synchronizers.base.syncstep import * |
| 8 | from core.models import Controller |
| 9 | from core.models import Image, ControllerImages |
| 10 | from xos.logger import observer_logger as logger |
| 11 | from synchronizers.base.ansible import * |
| 12 | import json |
| 13 | |
| 14 | class 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() |