blob: bb837db387afb685edd9ec40b1bed38cb4626717 [file] [log] [blame]
Tony Mack27c73902013-10-08 14:36:33 -04001import os
2import base64
3from django.db.models import F, Q
4from planetstack.config import Config
5from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.role import Role
Tony Mack91463d92014-06-19 20:42:03 -04007from core.models.site import SiteRole, Deployment, DeploymentRole
Tony Mack27c73902013-10-08 14:36:33 -04008from core.models.slice import SliceRole
9
10class SyncRoles(OpenStackSyncStep):
11 provides=[Role]
12 requested_interval=0
13
Sapan Bhatiab83643c2014-07-23 09:59:32 -040014 def fetch_pending(self, deleted):
15 # Deleting roles is not supported yet
16 if (deleted):
17 return []
18
Tony Mack04054f52013-10-14 17:15:57 -040019 site_roles = SiteRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack03742a72013-10-08 14:42:21 -040020 slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mackf4f16162013-10-08 15:30:35 -040021 deployment_roles = DeploymentRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack27c73902013-10-08 14:36:33 -040022
23 roles = []
24 for site_role in site_roles:
25 roles.append(site_role)
26 for slice_role in slice_roles:
27 roles.append(slice_role)
Tony Mackf4f16162013-10-08 15:30:35 -040028 for deployment_role in deployment_roles:
29 roles.append(deployment_role)
Tony Mack27c73902013-10-08 14:36:33 -040030
31 return roles
32
33
34 def sync_record(self, role):
Tony Mack0fef2272014-04-15 12:13:42 -040035 if not role.enacted:
36 deployments = Deployment.objects.all()
Scott Baker3949bc62014-05-12 10:42:16 -070037 for deployment in deployments:
Tony Mack0fef2272014-04-15 12:13:42 -040038 driver = self.driver.admin_driver(deployment=deployment.name)
39 driver.create_role(role.role)
Scott Baker3949bc62014-05-12 10:42:16 -070040 role.save()
41