Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 3 | from xos.config import Config |
| 4 | from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 5 | from synchronizers.new_base.syncstep import * |
| 6 | from synchronizers.new_base.ansible_helper import * |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 7 | from xos.logger import observer_logger as logger |
| 8 | import json |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 9 | from synchronizers.new_base.modelaccessor import * |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 10 | |
| 11 | class 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 Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 18 | 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 Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 24 | 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 | """ |