blob: b5e9f9a39c4103c5935a03d3b0fcec40e777ed19 [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
9class SyncSiteDeployments(OpenStackSyncStep):
10 requested_interval=0
Sapan Bhatia663626e2014-07-23 09:50:33 -040011 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,
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 Macke4be32f2014-03-11 20:45:25 -040033
Sapan Bhatia663626e2014-07-23 09:50:33 -040034 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)