Tony Mack | 06c8e47 | 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 | |
| 9 | class SyncControllerSites(OpenStackSyncStep): |
| 10 | requested_interval=0 |
| 11 | provides=[ControllerSiteDeployments, SiteDeployments] |
| 12 | |
| 13 | def sync_record(self, controller_site_deployment): |
| 14 | |
| 15 | template = os_template_env.get_template('sync_controller_site_deployments.yaml') |
| 16 | tenant_fields = {'endpoint':controller_site_deployment.controller.auth_url, |
| 17 | 'admin_user': controller_site_deployment.controller.admin_user, |
| 18 | 'admin_password': controller_site_deployment.controller.admin_password, |
| 19 | 'admin_tenant': 'admin', |
| 20 | 'tenant': controller_site_deployment.site_deployment.site.login_base, |
| 21 | 'tenant_description': controller_site_deployment.site_deployment.site.name} |
| 22 | |
| 23 | rendered = template.render(tenant_fields) |
| 24 | res = run_template('sync_controller_site_deployments.yaml', tenant_fields) |
| 25 | |
| 26 | if (len(res)==1): |
| 27 | controller_site_deployment.tenant_id = res[0]['id'] |
| 28 | controller_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']) |
| 33 | |
| 34 | def delete_record(self, controller_site_deployment): |
| 35 | if controller_site_deployment.tenant_id: |
| 36 | driver = self.driver.admin_driver(controller=controller_site_deployment.controller) |
| 37 | driver.delete_tenant(controller_site_deployment.tenant_id) |