blob: 67c5a94a88dd9fdba804030a17f2392331332bc4 [file] [log] [blame]
Matteo Scandolof0441032017-08-08 13:05:26 -07001# 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 Bakerb63ea792016-08-11 10:24:48 -070015import os
Andy Bavier384aa762018-05-03 15:55:38 -070016import urlparse
Scott Bakerb63ea792016-08-11 10:24:48 -070017import base64
Scott Baker8b75e852016-08-16 15:04:59 -070018from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
Scott Bakeraf599eb2017-03-21 12:43:26 -070019from synchronizers.new_base.syncstep import *
Scott Bakeraf599eb2017-03-21 12:43:26 -070020from synchronizers.new_base.ansible_helper import *
21from synchronizers.new_base.modelaccessor import *
Scott Bakerb63ea792016-08-11 10:24:48 -070022
23class SyncControllerImages(OpenStackSyncStep):
24 provides=[ControllerImages]
25 observes = ControllerImages
26 requested_interval=0
27 playbook='sync_controller_images.yaml'
28
Scott Bakerb63ea792016-08-11 10:24:48 -070029 def map_sync_inputs(self, controller_image):
Andy Bavier384aa762018-05-03 15:55:38 -070030 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 Bakerb63ea792016-08-11 10:24:48 -070038 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 Williams9cb1f3a2017-08-20 19:35:03 -070042 'admin_project': 'admin',
Scott Bakerb63ea792016-08-11 10:24:48 -070043 'domain': controller_image.controller.domain,
44 'name':controller_image.image.name,
Andy Bavier384aa762018-05-03 15:55:38 -070045 'filepath':filepath,
46 'location':location,
Scott Bakerb63ea792016-08-11 10:24:48 -070047 'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
48 }
49
Andy Bavier927f0c12018-05-15 17:07:14 -070050 return image_fields
Scott Bakerb63ea792016-08-11 10:24:48 -070051
52 def map_sync_outputs(self, controller_image, res):
Andy Bavier927f0c12018-05-15 17:07:14 -070053 image_id = res[-1]['id']
Scott Bakerb63ea792016-08-11 10:24:48 -070054 controller_image.glance_image_id = image_id
Andy Bavier927f0c12018-05-15 17:07:14 -070055 controller_image.backend_status = 'OK'
56 controller_image.backend_code = 1
Scott Bakerb63ea792016-08-11 10:24:48 -070057 controller_image.save()
agmimidia0a945a2018-11-05 17:10:55 +010058
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