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