blob: 600f0129f4920865cccc05d1eb92bf2b1d1eef83 [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 Mack06c8e472014-11-30 15:53:08 -05007from core.models.controllerusers import ControllerUsers
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 Mack06c8e472014-11-30 15:53:08 -050023 # sync slice memberships at all slice controllers
Scott Baker3949bc62014-05-12 10:42:16 -070024 logger.info("syncing slice privilege: %s %s" % (slice_memb.slice.name, slice_memb.user.email))
Tony Mack06c8e472014-11-30 15:53:08 -050025 slice_controllers = ControllerSlices.objects.filter(slice=slice_memb.slice)
26 for slice_controller in slice_controllers:
27 if not slice_controller.tenant_id:
Tony Mackac2c6172014-04-10 12:25:22 -040028 continue
Tony Mack06c8e472014-11-30 15:53:08 -050029 controller_users = ControllerUsers.objects.filter(controller=slice_controller.controller,
Tony Macke7045ca2014-04-15 12:14:09 -040030 user=slice_memb.user)
Tony Mack06c8e472014-11-30 15:53:08 -050031 if controller_users:
32 kuser_id = controller_users[0].kuser_id
33 driver = self.driver.admin_driver(controller=slice_controller.controller.name)
Tony Macke4be32f2014-03-11 20:45:25 -040034 driver.add_user_role(kuser_id,
Tony Mack06c8e472014-11-30 15:53:08 -050035 slice_controller.tenant_id,
Tony Macke4be32f2014-03-11 20:45:25 -040036 slice_memb.role.role)