blob: e3a20e987d24893566dbecd7f5b15bd5f361b22a [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
14 def fetch_pending(self):
Tony Mack04054f52013-10-14 17:15:57 -040015 site_roles = SiteRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack03742a72013-10-08 14:42:21 -040016 slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mackf4f16162013-10-08 15:30:35 -040017 deployment_roles = DeploymentRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack27c73902013-10-08 14:36:33 -040018
19 roles = []
20 for site_role in site_roles:
21 roles.append(site_role)
22 for slice_role in slice_roles:
23 roles.append(slice_role)
Tony Mackf4f16162013-10-08 15:30:35 -040024 for deployment_role in deployment_roles:
25 roles.append(deployment_role)
Tony Mack27c73902013-10-08 14:36:33 -040026
27 return roles
28
29
30 def sync_record(self, role):
Tony Mack0fef2272014-04-15 12:13:42 -040031 if not role.enacted:
32 deployments = Deployment.objects.all()
Scott Baker3949bc62014-05-12 10:42:16 -070033 for deployment in deployments:
Tony Mack0fef2272014-04-15 12:13:42 -040034 driver = self.driver.admin_driver(deployment=deployment.name)
35 driver.create_role(role.role)
Scott Baker3949bc62014-05-12 10:42:16 -070036 role.save()
37