blob: 91c0abbb78fb9b783af43321336365e3e8989d1d [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 Mack336e0f92014-11-30 15:53:08 -05007from core.models.site import SiteRole, Controller, ControllerRole
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 Mack336e0f92014-11-30 15:53:08 -050021 controller_roles = ControllerRole.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 Mack336e0f92014-11-30 15:53:08 -050028 for controller_role in controller_roles:
29 roles.append(controller_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:
Tony Mack336e0f92014-11-30 15:53:08 -050036 controllers = Controller.objects.all()
37 for controller in controllers:
38 driver = self.driver.admin_driver(controller=controller.name)
Tony Mack0fef2272014-04-15 12:13:42 -040039 driver.create_role(role.role)
Scott Baker3949bc62014-05-12 10:42:16 -070040 role.save()
41