blob: 8724841bb572e1183375700d533c7c2de2f79aa5 [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
Tony Mack91463d92014-06-19 20:42:03 -04006from core.models import User, UserDeployments, SitePrivilege, SiteDeployments
Sapan Bhatia24836f12013-08-27 10:16:05 -04007
8class SyncSitePrivileges(OpenStackSyncStep):
Tony Mackdacfb982013-09-24 21:57:16 -04009 requested_interval=0
10 provides=[SitePrivilege]
Tony Mack66646d52013-09-24 21:47:12 -040011
12 def fetch_pending(self):
Tony Mack31078dd2013-10-02 12:46:21 -040013 return SitePrivilege.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack66646d52013-09-24 21:47:12 -040014
Tony Mack37146d22013-10-21 11:02:51 -040015 def sync_record(self, site_priv):
Tony Macke4be32f2014-03-11 20:45:25 -040016 # sync site privileges at all site deployments
17 site_deployments = SiteDeployments.objects.filter(site=site_priv.site)
18 for site_deployment in site_deployments:
19 user_deployments = UserDeployments.objects.filter(deployment=site_deployment.deployment)
20 if user_deployments:
21 kuser_id = user_deployments[0].kuser_id
Tony Mackf77f1402014-04-02 07:06:53 -040022 driver = self.driver.admin_driver(deployment=site_deployment.deployment.name)
Tony Macke4be32f2014-03-11 20:45:25 -040023 driver.add_user_role(kuser_id,
24 site_deployment.tenant_id,
Tony Mackf77f1402014-04-02 07:06:53 -040025 site_priv.role.role)