blob: f12f4779c68d816777dd1bddc16e2757de46bc87 [file] [log] [blame]
Matteo Scandolof0441032017-08-08 13:05:26 -07001
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 Bakerb63ea792016-08-11 10:24:48 -070017import os
18import base64
Scott Bakerb63ea792016-08-11 10:24:48 -070019from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
Scott Bakeraf599eb2017-03-21 12:43:26 -070020from synchronizers.new_base.syncstep import *
21from synchronizers.new_base.ansible_helper import *
Scott Bakerb63ea792016-08-11 10:24:48 -070022import json
Scott Bakeraf599eb2017-03-21 12:43:26 -070023from synchronizers.new_base.modelaccessor import *
Scott Bakerb63ea792016-08-11 10:24:48 -070024
25class SyncControllerSites(OpenStackSyncStep):
26 requested_interval=0
27 provides=[Site]
28 observes=ControllerSite
29 playbook = 'sync_controller_sites.yaml'
30
31 def fetch_pending(self, deleted=False):
Scott Bakeraf599eb2017-03-21 12:43:26 -070032 lobjs = super(SyncControllerSites, self).fetch_pending(deleted)
33
34 if not deleted:
35 # filter out objects with null controllers
36 lobjs = [x for x in lobjs if x.controller]
37
Scott Bakerb63ea792016-08-11 10:24:48 -070038 return lobjs
39
40 def map_sync_inputs(self, controller_site):
41 tenant_fields = {'endpoint':controller_site.controller.auth_url,
Zack Williams9cb1f3a2017-08-20 19:35:03 -070042 'endpoint_v3': controller_site.controller.auth_url_v3,
43 'domain': controller_site.controller.domain,
44 'admin_user': controller_site.controller.admin_user,
45 'admin_password': controller_site.controller.admin_password,
46 'admin_tenant': controller_site.controller.admin_tenant,
47 'admin_project': 'admin',
48 'ansible_tag': '%s@%s'%(controller_site.site.login_base,controller_site.controller.name), # name of ansible playbook
49 'project': controller_site.site.login_base,
50 'project_description': controller_site.site.name}
Scott Bakerb63ea792016-08-11 10:24:48 -070051 return tenant_fields
52
53 def map_sync_outputs(self, controller_site, res):
Zack Williams2b1f7f82017-08-28 11:45:55 -070054 controller_site.tenant_id = res[0]['project']['id']
Sapan Bhatiab9e504c2017-08-29 18:39:53 -040055 controller_site.backend_status = 'OK'
56 controller_site.backend_code = 1
Scott Bakerb63ea792016-08-11 10:24:48 -070057 controller_site.save()
Zack Williams9cb1f3a2017-08-20 19:35:03 -070058
Scott Bakerb63ea792016-08-11 10:24:48 -070059 def delete_record(self, controller_site):
60 controller_register = json.loads(controller_site.controller.backend_register)
61 if (controller_register.get('disabled',False)):
62 raise InnocuousException('Controller %s is disabled'%controller_site.controller.name)
63
64 if controller_site.tenant_id:
65 driver = self.driver.admin_driver(controller=controller_site.controller)
66 driver.delete_tenant(controller_site.tenant_id)
67
68 """
69 Ansible does not support tenant deletion yet
70
71 import pdb
72 pdb.set_trace()
73 template = os_template_env.get_template('delete_controller_sites.yaml')
74 tenant_fields = {'endpoint':controller_site.controller.auth_url,
75 'admin_user': controller_site.controller.admin_user,
76 'admin_password': controller_site.controller.admin_password,
77 'admin_tenant': 'admin',
78 'ansible_tag': 'controller_sites/%s@%s'%(controller_site.controller_site.site.login_base,controller_site.controller_site.deployment.name), # name of ansible playbook
79 'tenant': controller_site.controller_site.site.login_base,
80 'delete': True}
81
82 rendered = template.render(tenant_fields)
83 res = run_template('sync_controller_sites.yaml', tenant_fields)
84
85 if (len(res)!=1):
86 raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
87 """