Matteo Scandolo | f044103 | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 17 | import os |
| 18 | import base64 |
Scott Baker | 8b75e85 | 2016-08-16 15:04:59 -0700 | [diff] [blame] | 19 | from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 20 | from synchronizers.new_base.syncstep import * |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 21 | from synchronizers.new_base.ansible_helper import * |
| 22 | from synchronizers.new_base.modelaccessor import * |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 23 | |
| 24 | class SyncControllerImages(OpenStackSyncStep): |
| 25 | provides=[ControllerImages] |
| 26 | observes = ControllerImages |
| 27 | requested_interval=0 |
| 28 | playbook='sync_controller_images.yaml' |
| 29 | |
| 30 | def fetch_pending(self, deleted): |
| 31 | if (deleted): |
| 32 | return [] |
| 33 | |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 34 | return super(SyncControllerImages, self).fetch_pending(deleted) |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 35 | |
| 36 | def map_sync_inputs(self, controller_image): |
| 37 | image_fields = {'endpoint':controller_image.controller.auth_url, |
| 38 | 'endpoint_v3': controller_image.controller.auth_url_v3, |
| 39 | 'admin_user':controller_image.controller.admin_user, |
| 40 | 'admin_password':controller_image.controller.admin_password, |
Zack Williams | 9cb1f3a | 2017-08-20 19:35:03 -0700 | [diff] [blame] | 41 | 'admin_project': 'admin', |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 42 | 'domain': controller_image.controller.domain, |
| 43 | 'name':controller_image.image.name, |
| 44 | 'filepath':controller_image.image.path, |
| 45 | 'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook |
| 46 | } |
| 47 | |
| 48 | return image_fields |
| 49 | |
| 50 | def map_sync_outputs(self, controller_image, res): |
| 51 | image_id = res[0]['id'] |
| 52 | controller_image.glance_image_id = image_id |
Sapan Bhatia | b9e504c | 2017-08-29 18:39:53 -0400 | [diff] [blame^] | 53 | controller_image.backend_status = 'OK' |
| 54 | controller_image.backend_code = 1 |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 55 | controller_image.save() |