Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
Tony Mack | ae7f30c | 2013-09-25 12:46:50 -0400 | [diff] [blame] | 3 | from django.db.models import F, Q |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 4 | from planetstack.config import Config |
Sapan Bhatia | 04c94ad | 2013-09-02 18:00:28 -0400 | [diff] [blame] | 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.slice import * |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 7 | from core.models.user import UserDeployments |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 8 | |
| 9 | class SyncSliceMemberships(OpenStackSyncStep): |
Tony Mack | ce79de0 | 2013-09-24 10:12:33 -0400 | [diff] [blame] | 10 | requested_interval=0 |
Tony Mack | 66646d5 | 2013-09-24 21:47:12 -0400 | [diff] [blame] | 11 | provides=[SlicePrivilege] |
| 12 | |
| 13 | def fetch_pending(self): |
| 14 | return SlicePrivilege.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| 15 | |
Tony Mack | 37146d2 | 2013-10-21 11:02:51 -0400 | [diff] [blame] | 16 | def sync_record(self, slice_memb): |
Tony Mack | ce79de0 | 2013-09-24 10:12:33 -0400 | [diff] [blame] | 17 | 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 Mack | 0036707 | 2013-10-08 18:09:30 -0400 | [diff] [blame] | 20 | slice_memb.role.role) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 21 | |
| 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 Mack | f77f140 | 2014-04-02 07:06:53 -0400 | [diff] [blame] | 28 | driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 29 | driver.add_user_role(kuser_id, |
| 30 | slice_deployment.tenant_id, |
| 31 | slice_memb.role.role) |