blob: 78da7b2215952d8b3dd3e7e7b571ba3ead3f2f5b [file] [log] [blame]
import os
import base64
from django.db.models import F, Q
from planetstack.config import Config
from observer.openstacksyncstep import OpenStackSyncStep
from core.models import User, UserDeployment, SitePrivilege, SiteDeployment
class SyncSitePrivileges(OpenStackSyncStep):
requested_interval=0
provides=[SitePrivilege]
def fetch_pending(self, deleted):
# Deleting site privileges is not supported yet
if (deleted):
return []
return SitePrivilege.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
def sync_record(self, site_priv):
# sync site privileges at all site deployments
site_deployments = SiteDeployment.objects.filter(site=site_priv.site)
for site_deployment in site_deployments:
user_deployments = UserDeployment.objects.filter(deployment=site_deployment.deployment)
if user_deployments:
kuser_id = user_deployments[0].kuser_id
driver = self.driver.admin_driver(deployment=site_deployment.deployment.name)
driver.add_user_role(kuser_id,
site_deployment.tenant_id,
site_priv.role.role)