blob: ba489aaeaa37cf4b3f782881fd279745fd03fc10 [file] [log] [blame]
Scott Bakerb63ea792016-08-11 10:24:48 -07001import os
2import base64
Scott Bakerb63ea792016-08-11 10:24:48 -07003from xos.config import Config
4from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
Scott Bakeraf599eb2017-03-21 12:43:26 -07005from synchronizers.new_base.syncstep import *
6from synchronizers.new_base.ansible_helper import *
Scott Bakerb63ea792016-08-11 10:24:48 -07007from xos.logger import observer_logger as logger
8import json
Scott Bakeraf599eb2017-03-21 12:43:26 -07009from synchronizers.new_base.modelaccessor import *
Scott Bakerb63ea792016-08-11 10:24:48 -070010
11class SyncControllerSites(OpenStackSyncStep):
12 requested_interval=0
13 provides=[Site]
14 observes=ControllerSite
15 playbook = 'sync_controller_sites.yaml'
16
17 def fetch_pending(self, deleted=False):
Scott Bakeraf599eb2017-03-21 12:43:26 -070018 lobjs = super(SyncControllerSites, self).fetch_pending(deleted)
19
20 if not deleted:
21 # filter out objects with null controllers
22 lobjs = [x for x in lobjs if x.controller]
23
Scott Bakerb63ea792016-08-11 10:24:48 -070024 return lobjs
25
26 def map_sync_inputs(self, controller_site):
27 tenant_fields = {'endpoint':controller_site.controller.auth_url,
28 'endpoint_v3': controller_site.controller.auth_url_v3,
29 'domain': controller_site.controller.domain,
30 'admin_user': controller_site.controller.admin_user,
31 'admin_password': controller_site.controller.admin_password,
32 'admin_tenant': controller_site.controller.admin_tenant,
33 'ansible_tag': '%s@%s'%(controller_site.site.login_base,controller_site.controller.name), # name of ansible playbook
34 'tenant': controller_site.site.login_base,
35 'tenant_description': controller_site.site.name}
36 return tenant_fields
37
38 def map_sync_outputs(self, controller_site, res):
39 controller_site.tenant_id = res[0]['id']
40 controller_site.backend_status = '1 - OK'
41 controller_site.save()
42
43 def delete_record(self, controller_site):
44 controller_register = json.loads(controller_site.controller.backend_register)
45 if (controller_register.get('disabled',False)):
46 raise InnocuousException('Controller %s is disabled'%controller_site.controller.name)
47
48 if controller_site.tenant_id:
49 driver = self.driver.admin_driver(controller=controller_site.controller)
50 driver.delete_tenant(controller_site.tenant_id)
51
52 """
53 Ansible does not support tenant deletion yet
54
55 import pdb
56 pdb.set_trace()
57 template = os_template_env.get_template('delete_controller_sites.yaml')
58 tenant_fields = {'endpoint':controller_site.controller.auth_url,
59 'admin_user': controller_site.controller.admin_user,
60 'admin_password': controller_site.controller.admin_password,
61 'admin_tenant': 'admin',
62 'ansible_tag': 'controller_sites/%s@%s'%(controller_site.controller_site.site.login_base,controller_site.controller_site.deployment.name), # name of ansible playbook
63 'tenant': controller_site.controller_site.site.login_base,
64 'delete': True}
65
66 rendered = template.render(tenant_fields)
67 res = run_template('sync_controller_sites.yaml', tenant_fields)
68
69 if (len(res)!=1):
70 raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
71 """