blob: 557c2efc65a20d99f1e454a077cbc5d70f48ba4b [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
29 def fetch_pending(self, deleted):
30 if (deleted):
31 return []
32
Scott Bakeraf599eb2017-03-21 12:43:26 -070033 return super(SyncControllerImages, self).fetch_pending(deleted)
Scott Bakerb63ea792016-08-11 10:24:48 -070034
35 def map_sync_inputs(self, controller_image):
Andy Bavier384aa762018-05-03 15:55:38 -070036 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 Bakerb63ea792016-08-11 10:24:48 -070044 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 Williams9cb1f3a2017-08-20 19:35:03 -070048 'admin_project': 'admin',
Scott Bakerb63ea792016-08-11 10:24:48 -070049 'domain': controller_image.controller.domain,
50 'name':controller_image.image.name,
Andy Bavier384aa762018-05-03 15:55:38 -070051 'filepath':filepath,
52 'location':location,
Scott Bakerb63ea792016-08-11 10:24:48 -070053 'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
54 }
55
Andy Bavier927f0c12018-05-15 17:07:14 -070056 return image_fields
Scott Bakerb63ea792016-08-11 10:24:48 -070057
58 def map_sync_outputs(self, controller_image, res):
Andy Bavier927f0c12018-05-15 17:07:14 -070059 image_id = res[-1]['id']
Scott Bakerb63ea792016-08-11 10:24:48 -070060 controller_image.glance_image_id = image_id
Andy Bavier927f0c12018-05-15 17:07:14 -070061 controller_image.backend_status = 'OK'
62 controller_image.backend_code = 1
Scott Bakerb63ea792016-08-11 10:24:48 -070063 controller_image.save()