blob: 8b2d3b880b5e9f31126b33319a81a1652d0096b6 [file] [log] [blame]
Tony Macke4be32f2014-03-11 20:45:25 -04001import os
2import base64
3from django.db.models import F, Q
4from planetstack.config import Config
5from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.site import *
Sapan Bhatia475c5972014-11-05 10:32:41 -05007from observer.ansible import *
Tony Macke4be32f2014-03-11 20:45:25 -04008
Sapan Bhatia39e85582014-11-19 15:07:36 -05009class SyncSiteDeployments(OpenStackSyncStep):
Tony Macke4be32f2014-03-11 20:45:25 -040010 requested_interval=0
Sapan Bhatia39e85582014-11-19 15:07:36 -050011 provides=[SiteDeployments, Site]
Tony Macke4be32f2014-03-11 20:45:25 -040012
13 def sync_record(self, site_deployment):
Sapan Bhatia475c5972014-11-05 10:32:41 -050014
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,
Sapan5bfab5e2014-12-03 00:04:58 -050021 'ansible_tag': '%s@%s'%(site_deployment.site.login_base,site_deployment.deployment.name), # name of ansible playbook
Sapan Bhatia475c5972014-11-05 10:32:41 -050022 'tenant_description': site_deployment.site.name}
23
24 rendered = template.render(tenant_fields)
Sapan5bfab5e2014-12-03 00:04:58 -050025 res = run_template('sync_site_deployments.yaml', tenant_fields, path='site_deployments')
Sapan Bhatia475c5972014-11-05 10:32:41 -050026
27 if (len(res)==1):
28 site_deployment.tenant_id = res[0]['id']
29 site_deployment.save()
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'])
Tony Macke4be32f2014-03-11 20:45:25 -040034
Sapan Bhatia663626e2014-07-23 09:50:33 -040035 def delete_record(self, site_deployment):
36 if site_deployment.tenant_id:
37 driver = self.driver.admin_driver(deployment=site_deployment.deployment.name)
38 driver.delete_tenant(site_deployment.tenant_id)