Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [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 * |
Sapan Bhatia | 475c597 | 2014-11-05 10:32:41 -0500 | [diff] [blame] | 7 | from observer.ansible import * |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 8 | |
| 9 | class SyncSiteDeployments(OpenStackSyncStep): |
| 10 | requested_interval=0 |
Sapan Bhatia | 663626e | 2014-07-23 09:50:33 -0400 | [diff] [blame] | 11 | provides=[SiteDeployments, Site] |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 12 | |
| 13 | def sync_record(self, site_deployment): |
Sapan Bhatia | 475c597 | 2014-11-05 10:32:41 -0500 | [diff] [blame] | 14 | |
| 15 | template = os_template_env.get_template('sync_site_deployments.yaml') |
| 16 | tenant_fields = {'endpoint':site_deployment.deployment.auth_url, |
| 17 | 'admin_user': site_deployment.deployment.admin_user, |
| 18 | 'admin_password': site_deployment.deployment.admin_password, |
| 19 | 'admin_tenant': 'admin', |
| 20 | 'tenant': site_deployment.site.login_base, |
| 21 | 'tenant_description': site_deployment.site.name} |
| 22 | |
| 23 | rendered = template.render(tenant_fields) |
| 24 | res = run_template('sync_site_deployments.yaml', tenant_fields) |
| 25 | |
| 26 | if (len(res)==1): |
| 27 | site_deployment.tenant_id = res[0]['id'] |
| 28 | site_deployment.save() |
| 29 | elif (len(res)): |
| 30 | raise Exception('Could not assign roles for user %s'%tenant_fields['tenant']) |
| 31 | else: |
| 32 | raise Exception('Could not create or update user %s'%tenant_fields['tenant']) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 33 | |
Sapan Bhatia | 663626e | 2014-07-23 09:50:33 -0400 | [diff] [blame] | 34 | def delete_record(self, site_deployment): |
| 35 | if site_deployment.tenant_id: |
| 36 | driver = self.driver.admin_driver(deployment=site_deployment.deployment.name) |
| 37 | driver.delete_tenant(site_deployment.tenant_id) |