Scott Baker | 76a840e | 2015-02-11 21:38:09 -0800 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from django.db.models import F, Q |
| 4 | from xos.config import Config |
| 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.role import Role |
| 7 | from core.models.site import SiteRole, Controller, ControllerRole |
| 8 | from core.models.slice import SliceRole |
| 9 | |
| 10 | class 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 | |