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 * |
| 7 | |
| 8 | class SyncSiteDeployments(OpenStackSyncStep): |
| 9 | requested_interval=0 |
| 10 | provides=[Site, SiteDeployments] |
| 11 | |
| 12 | def fetch_pending(self): |
| 13 | return SiteDeployments.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| 14 | |
| 15 | def sync_record(self, site_deployment): |
| 16 | if not site_deployment.tenant_id: |
| 17 | driver = self.driver.admin_driver(deployment=site_deployment.deployment.name) |
| 18 | tenant = driver.create_tenant(tenant_name=site_deployment.site.login_base, |
| 19 | description=site_deployment.site.name, |
| 20 | enabled=site_deployment.site.enabled) |
| 21 | site_deployment.tenant_id = tenant.id |
| 22 | site_deployment.save() |
| 23 | elif site_deployment.site.id and site_deployment.tenant_id: |
Tony Mack | a16cfb2 | 2014-06-19 22:00:22 -0400 | [diff] [blame] | 24 | driver = self.driver.admin_driver(deployment=site_deployment.deployment.name) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 25 | driver.update_tenant(site_deployment.tenant_id, |
| 26 | description=site_deployment.site.name, |
| 27 | enabled=site_deployment.site.enabled) |
| 28 | |