blob: 08b7b6a65d633a0c4f57f9feb8a6acd4748e6735 [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
Sapan Bhatia24836f12013-08-27 10:16:05 -04008
9class SyncSliceMemberships(OpenStackSyncStep):
Tony Mackce79de02013-09-24 10:12:33 -040010 requested_interval=0
Tony Mack66646d52013-09-24 21:47:12 -040011 provides=[SlicePrivilege]
12
13 def fetch_pending(self):
14 return SlicePrivilege.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
15
Tony Mack37146d22013-10-21 11:02:51 -040016 def sync_record(self, slice_memb):
Tony Mackce79de02013-09-24 10:12:33 -040017 if slice_memb.user.kuser_id and slice_memb.slice.tenant_id:
18 self.driver.add_user_role(slice_memb.user.kuser_id,
19 slice_memb.slice.tenant_id,
Tony Mack00367072013-10-08 18:09:30 -040020 slice_memb.role.role)
Tony Macke4be32f2014-03-11 20:45:25 -040021
22 # sync slice memberships at all slice deployments
23 slice_deployments = SliceDeployments.objects.filter(slice=slice_memb.slice)
24 for slice_deployment in slice_deployments:
25 user_deployments = UserDeployments.objects.filter(deployment=slice_deployment.deployment)
26 if user_deployments:
27 kuser_id = user_deployments[0].kuser_id
Tony Mackf77f1402014-04-02 07:06:53 -040028 driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name)
Tony Macke4be32f2014-03-11 20:45:25 -040029 driver.add_user_role(kuser_id,
30 slice_deployment.tenant_id,
31 slice_memb.role.role)