blob: b6b16382d36e4f4b391a8dcb254c3a55b5e4a799 [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 Macke4be32f2014-03-11 20:45:25 -040017 # sync slice memberships at all slice deployments
18 slice_deployments = SliceDeployments.objects.filter(slice=slice_memb.slice)
19 for slice_deployment in slice_deployments:
Tony Mackac2c6172014-04-10 12:25:22 -040020 if not slice_deployment.tenant_id:
21 continue
Tony Macke7045ca2014-04-15 12:14:09 -040022 user_deployments = UserDeployments.objects.filter(deployment=slice_deployment.deployment,
23 user=slice_memb.user)
Tony Macke4be32f2014-03-11 20:45:25 -040024 if user_deployments:
25 kuser_id = user_deployments[0].kuser_id
Tony Mackf77f1402014-04-02 07:06:53 -040026 driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name)
Tony Macke4be32f2014-03-11 20:45:25 -040027 driver.add_user_role(kuser_id,
28 slice_deployment.tenant_id,
29 slice_memb.role.role)