blob: 24aa76f8f8c1063192fd38cdf486fe90837e3039 [file] [log] [blame]
Scott Bakerbba67b62019-01-28 17:38:21 -08001# 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
15
16import os
17import base64
18import json
19from xossynchronizer.steps.syncstep import SyncStep
Scott Bakerbba67b62019-01-28 17:38:21 -080020
21class SyncControllerSites(SyncStep):
22 requested_interval = 0
Scott Bakerc2fddaa2019-01-30 15:45:03 -080023 observes = "ControllerSite"
Scott Bakerbba67b62019-01-28 17:38:21 -080024 playbook = "sync_controller_sites.yaml"
25
26 def fetch_pending(self, deleted=False):
27 lobjs = super(SyncControllerSites, self).fetch_pending(deleted)
28
29 if not deleted:
30 # filter out objects with null controllers
31 lobjs = [x for x in lobjs if x.controller]
32
33 return lobjs
34
35 def map_sync_inputs(self, controller_site):
36 tenant_fields = {
37 "endpoint": controller_site.controller.auth_url,
38 "endpoint_v3": controller_site.controller.auth_url_v3,
39 "domain": controller_site.controller.domain,
40 "admin_user": controller_site.controller.admin_user,
41 "admin_password": controller_site.controller.admin_password,
42 "admin_tenant": controller_site.controller.admin_tenant,
43 # name of ansible playbook
44 "ansible_tag": "%s@%s"
45 % (controller_site.site.login_base, controller_site.controller.name),
46 "tenant": controller_site.site.login_base,
47 "tenant_description": controller_site.site.name,
48 }
49 return tenant_fields
50
51 def map_sync_outputs(self, controller_site, res):
52 controller_site.tenant_id = res[0]["id"]
53 controller_site.backend_status = "1 - OK"
54 controller_site.save()
55
56 def delete_record(self, controller_site):
57 controller_register = json.loads(controller_site.controller.backend_register)
58 if controller_register.get("disabled", False):
59 raise InnocuousException(
60 "Controller %s is disabled" % controller_site.controller.name
61 )
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 """