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 *
9 class SyncSiteDeployments(OpenStackSyncStep):
11 provides=[SiteDeployments, Site]
13 def sync_record(self, site_deployment):
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}
23 rendered = template.render(tenant_fields)
24 res = run_template('sync_site_deployments.yaml', tenant_fields)
27 site_deployment.tenant_id = res[0]['id']
28 site_deployment.save()
30 raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
32 raise Exception('Could not create or update user %s'%tenant_fields['tenant'])
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)