blob: 38bd26c33abb72f90a723f70166a5a93812fad5c [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.slice import *
Tony Macke4be32f2014-03-11 20:45:25 -04007from core.models.user import UserDeployments
Scott Baker3949bc62014-05-12 10:42:16 -07008from util.logger import Logger, logging
9
10logger = Logger(level=logging.INFO)
Sapan Bhatia24836f12013-08-27 10:16:05 -040011
12class SyncSliceMemberships(OpenStackSyncStep):
Tony Mackce79de02013-09-24 10:12:33 -040013 requested_interval=0
Tony Mack66646d52013-09-24 21:47:12 -040014 provides=[SlicePrivilege]
15
16 def fetch_pending(self):
17 return SlicePrivilege.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
18
Tony Mack37146d22013-10-21 11:02:51 -040019 def sync_record(self, slice_memb):
Tony Macke4be32f2014-03-11 20:45:25 -040020 # sync slice memberships at all slice deployments
Scott Baker3949bc62014-05-12 10:42:16 -070021 logger.info("syncing slice privilege: %s %s" % (slice_memb.slice.name, slice_memb.user.email))
Tony Macke4be32f2014-03-11 20:45:25 -040022 slice_deployments = SliceDeployments.objects.filter(slice=slice_memb.slice)
23 for slice_deployment in slice_deployments:
Tony Mackac2c6172014-04-10 12:25:22 -040024 if not slice_deployment.tenant_id:
25 continue
Tony Macke7045ca2014-04-15 12:14:09 -040026 user_deployments = UserDeployments.objects.filter(deployment=slice_deployment.deployment,
27 user=slice_memb.user)
Tony Macke4be32f2014-03-11 20:45:25 -040028 if user_deployments:
29 kuser_id = user_deployments[0].kuser_id
Tony Mackf77f1402014-04-02 07:06:53 -040030 driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name)
Tony Macke4be32f2014-03-11 20:45:25 -040031 driver.add_user_role(kuser_id,
32 slice_deployment.tenant_id,
33 slice_memb.role.role)