blob: ca85d571cf25fbec4bc37983b6fae345845151b2 [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
Scott Baker3949bc62014-05-12 10:42:16 -07009from core.models.deployment import Deployment, 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()
Scott Baker3949bc62014-05-12 10:42:16 -070034 for deployment in deployments:
Tony Mack0fef2272014-04-15 12:13:42 -040035 driver = self.driver.admin_driver(deployment=deployment.name)
36 driver.create_role(role.role)
Scott Baker3949bc62014-05-12 10:42:16 -070037 role.save()
38