Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
Tony Mack | ae7f30c | 2013-09-25 12:46:50 -0400 | [diff] [blame^] | 3 | from django.db.models import F, Q |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 4 | from planetstack.config import Config |
Sapan Bhatia | 04c94ad | 2013-09-02 18:00:28 -0400 | [diff] [blame] | 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.site import Site |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 7 | |
| 8 | class SyncSites(OpenStackSyncStep): |
Tony Mack | dacfb98 | 2013-09-24 21:57:16 -0400 | [diff] [blame] | 9 | provides=[Site] |
| 10 | requested_interval=0 |
Tony Mack | 66646d5 | 2013-09-24 21:47:12 -0400 | [diff] [blame] | 11 | |
| 12 | def fetch_pending(self): |
| 13 | return Site.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| 14 | |
Tony Mack | dacfb98 | 2013-09-24 21:57:16 -0400 | [diff] [blame] | 15 | def sync_record(self, site): |
| 16 | save_site = False |
| 17 | if not site.tenant_id: |
| 18 | tenant = self.driver.create_tenant(tenant_name=site.login_base, |
| 19 | description=site.name, |
| 20 | enabled=site.enabled) |
| 21 | site.tenant_id = tenant.id |
| 22 | save_site = True |
| 23 | # XXX - What's caller? |
| 24 | # self.driver.add_user_role(self.caller.kuser_id, tenant.id, 'admin') |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 25 | |
Tony Mack | dacfb98 | 2013-09-24 21:57:16 -0400 | [diff] [blame] | 26 | # update the record |
| 27 | if site.id and site.tenant_id: |
| 28 | self.driver.update_tenant(site.tenant_id, |
| 29 | description=site.name, |
| 30 | enabled=site.enabled) |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 31 | |
Tony Mack | dacfb98 | 2013-09-24 21:57:16 -0400 | [diff] [blame] | 32 | if (save_site): |
| 33 | site.save() # |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 34 | |