blob: 0bd26c65542f481a027dbbccc17563257c9101fb [file] [log] [blame]
Scott Baker76a840e2015-02-11 21:38:09 -08001import os
2import base64
3from django.db.models import F, Q
4from xos.config import Config
5from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.role import Role
7from core.models.site import SiteRole, Controller, ControllerRole
8from core.models.slice import SliceRole
9
10class SyncRoles(OpenStackSyncStep):
11 provides=[Role]
12 requested_interval=0
13 observes=Role
14
15 def fetch_pending(self, deleted):
16 # Deleting roles is not supported yet
17 if (deleted):
18 return []
19
20 site_roles = SiteRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
21 slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
22 controller_roles = ControllerRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
23
24 roles = []
25 for site_role in site_roles:
26 roles.append(site_role)
27 for slice_role in slice_roles:
28 roles.append(slice_role)
29 for controller_role in controller_roles:
30 roles.append(controller_role)
31
32 return roles
33
34
35 def sync_record(self, role):
36 if not role.enacted:
37 controllers = Controller.objects.all()
38 for controller in controllers:
39 driver = self.driver.admin_driver(controller=controller)
40 driver.create_role(role.role)
41 role.save()
42