Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from django.db.models import F, Q |
| 4 | from planetstack.config import Config |
| 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.site import * |
| 7 | from observer.ansible import * |
| 8 | |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 9 | class SyncControllerSiteDeployments(OpenStackSyncStep): |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 10 | requested_interval=0 |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 11 | provides=[SiteDeployments] |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 12 | |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 13 | def sync_record(self, site_deployment): |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 14 | |
| 15 | template = os_template_env.get_template('sync_controller_site_deployments.yaml') |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 16 | tenant_fields = {'endpoint':site_deployment.controller.auth_url, |
| 17 | 'admin_user': site_deployment.controller.admin_user, |
| 18 | 'admin_password': site_deployment.controller.admin_password, |
| 19 | 'admin_tenant': site_deployment.controller.admin_tenant, |
| 20 | 'ansible_tag': '%s@%s'%(site_deployment.site.login_base,site_deployment.site_deployment.deployment.name), # name of ansible playbook |
| 21 | 'tenant': site_deployment.site.login_base, |
| 22 | 'tenant_description': site_deployment.site.name} |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 23 | |
| 24 | rendered = template.render(tenant_fields) |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 25 | res = run_template('sync_controller_site_deployments.yaml', tenant_fields, path='controller_site_deployments') |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 26 | |
| 27 | if (len(res)==1): |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 28 | site_deployment.tenant_id = res[0]['id'] |
| 29 | site_deployment.save() |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 30 | elif (len(res)): |
| 31 | raise Exception('Could not assign roles for user %s'%tenant_fields['tenant']) |
| 32 | else: |
| 33 | raise Exception('Could not create or update user %s'%tenant_fields['tenant']) |
| 34 | |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 35 | def delete_record(self, site_deployment): |
| 36 | if site_deployment.tenant_id: |
| 37 | driver = self.driver.admin_driver(controller=site_deployment.controller) |
| 38 | driver.delete_tenant(site_deployment.tenant_id) |
Sapan Bhatia | f2378a8 | 2014-12-21 02:33:52 -0500 | [diff] [blame] | 39 | |
| 40 | """ |
| 41 | Ansible does not support tenant deletion yet |
| 42 | |
| 43 | import pdb |
| 44 | pdb.set_trace() |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 45 | template = os_template_env.get_template('delete_site_deployments.yaml') |
| 46 | tenant_fields = {'endpoint':site_deployment.controller.auth_url, |
| 47 | 'admin_user': site_deployment.controller.admin_user, |
| 48 | 'admin_password': site_deployment.controller.admin_password, |
Sapan Bhatia | f2378a8 | 2014-12-21 02:33:52 -0500 | [diff] [blame] | 49 | 'admin_tenant': 'admin', |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 50 | 'ansible_tag': 'site_deployments/%s@%s'%(site_deployment.site_deployment.site.login_base,site_deployment.site_deployment.deployment.name), # name of ansible playbook |
| 51 | 'tenant': site_deployment.site_deployment.site.login_base, |
Sapan Bhatia | f2378a8 | 2014-12-21 02:33:52 -0500 | [diff] [blame] | 52 | 'delete': True} |
| 53 | |
| 54 | rendered = template.render(tenant_fields) |
Tony Mack | 7f542c6 | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 55 | res = run_template('sync_site_deployments.yaml', tenant_fields) |
Sapan Bhatia | f2378a8 | 2014-12-21 02:33:52 -0500 | [diff] [blame] | 56 | |
| 57 | if (len(res)!=1): |
| 58 | raise Exception('Could not assign roles for user %s'%tenant_fields['tenant']) |
| 59 | """ |