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 | |
Andy Bavier | 384aa76 | 2018-05-03 15:55:38 -0700 | [diff] [blame] | 15 | import urlparse |
Scott Baker | c808c67 | 2019-02-04 11:38:20 -0800 | [diff] [blame] | 16 | from openstacksyncstep import OpenStackSyncStep |
| 17 | from xossynchronizer.modelaccessor import * |
| 18 | from xosconfig import Config |
| 19 | from multistructlog import create_logger |
| 20 | |
| 21 | log = create_logger(Config().get('logging')) |
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 | |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 29 | def map_sync_inputs(self, controller_image): |
Andy Bavier | 384aa76 | 2018-05-03 15:55:38 -0700 | [diff] [blame] | 30 | if controller_image.image.path.startswith("http"): |
| 31 | location = controller_image.image.path |
| 32 | a = urlparse.urlparse(location) |
| 33 | filepath = "/opt/xos/images" + a.path |
| 34 | else: |
| 35 | filepath = controller_image.image.path |
| 36 | location = None |
| 37 | |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 38 | image_fields = {'endpoint':controller_image.controller.auth_url, |
| 39 | 'endpoint_v3': controller_image.controller.auth_url_v3, |
| 40 | 'admin_user':controller_image.controller.admin_user, |
| 41 | 'admin_password':controller_image.controller.admin_password, |
Zack Williams | 9cb1f3a | 2017-08-20 19:35:03 -0700 | [diff] [blame] | 42 | 'admin_project': 'admin', |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 43 | 'domain': controller_image.controller.domain, |
| 44 | 'name':controller_image.image.name, |
Andy Bavier | 384aa76 | 2018-05-03 15:55:38 -0700 | [diff] [blame] | 45 | 'filepath':filepath, |
| 46 | 'location':location, |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 47 | 'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook |
| 48 | } |
| 49 | |
Andy Bavier | 927f0c1 | 2018-05-15 17:07:14 -0700 | [diff] [blame] | 50 | return image_fields |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 51 | |
| 52 | def map_sync_outputs(self, controller_image, res): |
Andy Bavier | 927f0c1 | 2018-05-15 17:07:14 -0700 | [diff] [blame] | 53 | image_id = res[-1]['id'] |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 54 | controller_image.glance_image_id = image_id |
Andy Bavier | 927f0c1 | 2018-05-15 17:07:14 -0700 | [diff] [blame] | 55 | controller_image.backend_status = 'OK' |
| 56 | controller_image.backend_code = 1 |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 57 | controller_image.save() |
agmimidi | a0a945a | 2018-11-05 17:10:55 +0100 | [diff] [blame] | 58 | |
| 59 | def map_delete_inputs (self, controller_image): |
| 60 | if controller_image.image.path.startswith("http"): |
| 61 | location = controller_image.image.path |
| 62 | a = urlparse.urlparse(location) |
| 63 | filepath = "/opt/xos/images" + a.path |
| 64 | else: |
| 65 | filepath = controller_image.image.path |
| 66 | location = None |
| 67 | |
| 68 | image_fields = {'endpoint':controller_image.controller.auth_url, |
| 69 | 'endpoint_v3': controller_image.controller.auth_url_v3, |
| 70 | 'domain': controller_image.controller.domain, |
| 71 | 'admin_user': controller_image.controller.admin_user, |
| 72 | 'admin_password': controller_image.controller.admin_password, |
| 73 | 'admin_project': 'admin', |
| 74 | 'domain': controller_image.controller.domain, |
| 75 | 'name':controller_image.image.name, |
| 76 | 'filepath':filepath, |
| 77 | 'location':location, |
| 78 | 'ansible_tag':'%s@%s'%(controller_image.image.name,controller_image.controller.name), |
| 79 | 'delete': True} |
| 80 | return image_fields |