blob: 5dc30d99ad539e475496e9f4883024f7ffaaffe2 [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
7from core.models.site import SiteRole
8from core.models.slice import SliceRole
Tony Mackf4f16162013-10-08 15:30:35 -04009from core.models.deployment import DeploymentRole
Tony Mack27c73902013-10-08 14:36:33 -040010
11class SyncRoles(OpenStackSyncStep):
12 provides=[Role]
13 requested_interval=0
14
15 def fetch_pending(self):
Tony Mack04054f52013-10-14 17:15:57 -040016 site_roles = SiteRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack03742a72013-10-08 14:42:21 -040017 slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mackf4f16162013-10-08 15:30:35 -040018 deployment_roles = DeploymentRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack27c73902013-10-08 14:36:33 -040019
20 roles = []
21 for site_role in site_roles:
22 roles.append(site_role)
23 for slice_role in slice_roles:
24 roles.append(slice_role)
Tony Mackf4f16162013-10-08 15:30:35 -040025 for deployment_role in deployment_roles:
26 roles.append(deployment_role)
Tony Mack27c73902013-10-08 14:36:33 -040027
28 return roles
29
30
31 def sync_record(self, role):
Tony Mack0fef2272014-04-15 12:13:42 -040032 if not role.enacted:
33 deployments = Deployment.objects.all()
34 for deployment in deployments:
35 driver = self.driver.admin_driver(deployment=deployment.name)
36 driver.create_role(role.role)
37 role.save()