blob: b1cd223d100ca70eadc24ee43b843f306d41bec7 [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 Mack91463d92014-06-19 20:42:03 -04007from core.models.userdeployments 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
Sapan Bhatiab83643c2014-07-23 09:59:32 -040016 def fetch_pending(self, deleted):
17 # Deleting site memberships is not supported yet
18 if (deleted):
19 return []
Tony Mack66646d52013-09-24 21:47:12 -040020 return SlicePrivilege.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
21
Tony Mack37146d22013-10-21 11:02:51 -040022 def sync_record(self, slice_memb):
Tony Macke4be32f2014-03-11 20:45:25 -040023 # sync slice memberships at all slice deployments
Scott Baker3949bc62014-05-12 10:42:16 -070024 logger.info("syncing slice privilege: %s %s" % (slice_memb.slice.name, slice_memb.user.email))
Tony Macke4be32f2014-03-11 20:45:25 -040025 slice_deployments = SliceDeployments.objects.filter(slice=slice_memb.slice)
26 for slice_deployment in slice_deployments:
Tony Mackac2c6172014-04-10 12:25:22 -040027 if not slice_deployment.tenant_id:
28 continue
Tony Macke7045ca2014-04-15 12:14:09 -040029 user_deployments = UserDeployments.objects.filter(deployment=slice_deployment.deployment,
30 user=slice_memb.user)
Tony Macke4be32f2014-03-11 20:45:25 -040031 if user_deployments:
32 kuser_id = user_deployments[0].kuser_id
Tony Mackf77f1402014-04-02 07:06:53 -040033 driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name)
Tony Macke4be32f2014-03-11 20:45:25 -040034 driver.add_user_role(kuser_id,
35 slice_deployment.tenant_id,
36 slice_memb.role.role)