blob: 18a784a6b43897378c79cfb539323450a3b834be [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):
32 save_role = False
33 if not role.krole_id:
34 krole = self.driver.create_role(role.role)
35 role.krole_id = krole.id
36 save_role = True
37
38 if (save_role):
39 role.save()
40