blob: c0adc42fa90c935df2246768d28ebc441ff4c49e [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):
54 controller_site.tenant_id = res[0]['id']
55 controller_site.backend_status = '1 - OK'
56 controller_site.save()
Zack Williams9cb1f3a2017-08-20 19:35:03 -070057
Scott Bakerb63ea792016-08-11 10:24:48 -070058 def delete_record(self, controller_site):
59 controller_register = json.loads(controller_site.controller.backend_register)
60 if (controller_register.get('disabled',False)):
61 raise InnocuousException('Controller %s is disabled'%controller_site.controller.name)
62
63 if controller_site.tenant_id:
64 driver = self.driver.admin_driver(controller=controller_site.controller)
65 driver.delete_tenant(controller_site.tenant_id)
66
67 """
68 Ansible does not support tenant deletion yet
69
70 import pdb
71 pdb.set_trace()
72 template = os_template_env.get_template('delete_controller_sites.yaml')
73 tenant_fields = {'endpoint':controller_site.controller.auth_url,
74 'admin_user': controller_site.controller.admin_user,
75 'admin_password': controller_site.controller.admin_password,
76 'admin_tenant': 'admin',
77 'ansible_tag': 'controller_sites/%s@%s'%(controller_site.controller_site.site.login_base,controller_site.controller_site.deployment.name), # name of ansible playbook
78 'tenant': controller_site.controller_site.site.login_base,
79 'delete': True}
80
81 rendered = template.render(tenant_fields)
82 res = run_template('sync_controller_sites.yaml', tenant_fields)
83
84 if (len(res)!=1):
85 raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
86 """