blob: 2013c6d54fd2d266a14c2a0c161cdddab4251d92 [file] [log] [blame]
Sapan Bhatia24836f12013-08-27 10:16:05 -04001import os
2import base64
Tony Mackae7f30c2013-09-25 12:46:50 -04003from django.db.models import F, Q
Sapan Bhatia24836f12013-08-27 10:16:05 -04004from planetstack.config import Config
Sapan Bhatia04c94ad2013-09-02 18:00:28 -04005from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.site import Site
Sapan Bhatia24836f12013-08-27 10:16:05 -04007
8class SyncSites(OpenStackSyncStep):
Tony Mackdacfb982013-09-24 21:57:16 -04009 provides=[Site]
10 requested_interval=0
Tony Mack66646d52013-09-24 21:47:12 -040011
12 def fetch_pending(self):
13 return Site.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
14
Tony Mackdacfb982013-09-24 21:57:16 -040015 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 Bhatia24836f12013-08-27 10:16:05 -040025
Tony Mackdacfb982013-09-24 21:57:16 -040026 # 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 Bhatia24836f12013-08-27 10:16:05 -040031
Tony Mackdacfb982013-09-24 21:57:16 -040032 if (save_site):
33 site.save() #
Sapan Bhatia24836f12013-08-27 10:16:05 -040034