blob: 38bd26c33abb72f90a723f70166a5a93812fad5c [file] [log] [blame]
Scott Baker105b6b72014-05-12 10:40:25 -07001import os
2import base64
3from django.db.models import F, Q
4from planetstack.config import Config
5from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.slice import *
7from core.models.user import UserDeployments
8from util.logger import Logger, logging
9
10logger = Logger(level=logging.INFO)
11
12class SyncSliceMemberships(OpenStackSyncStep):
13 requested_interval=0
14 provides=[SlicePrivilege]
15
16 def fetch_pending(self):
17 return SlicePrivilege.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
18
19 def sync_record(self, slice_memb):
20 # sync slice memberships at all slice deployments
21 logger.info("syncing slice privilege: %s %s" % (slice_memb.slice.name, slice_memb.user.email))
22 slice_deployments = SliceDeployments.objects.filter(slice=slice_memb.slice)
23 for slice_deployment in slice_deployments:
24 if not slice_deployment.tenant_id:
25 continue
26 user_deployments = UserDeployments.objects.filter(deployment=slice_deployment.deployment,
27 user=slice_memb.user)
28 if user_deployments:
29 kuser_id = user_deployments[0].kuser_id
30 driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name)
31 driver.add_user_role(kuser_id,
32 slice_deployment.tenant_id,
33 slice_memb.role.role)