Tony Mack | 27c7390 | 2013-10-08 14:36:33 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from django.db.models import F, Q |
| 4 | from planetstack.config import Config |
| 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.role import Role |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 7 | from core.models.site import SiteRole, Controller, ControllerRole |
Tony Mack | 27c7390 | 2013-10-08 14:36:33 -0400 | [diff] [blame] | 8 | from core.models.slice import SliceRole |
| 9 | |
| 10 | class SyncRoles(OpenStackSyncStep): |
| 11 | provides=[Role] |
| 12 | requested_interval=0 |
| 13 | |
Sapan Bhatia | b83643c | 2014-07-23 09:59:32 -0400 | [diff] [blame] | 14 | def fetch_pending(self, deleted): |
| 15 | # Deleting roles is not supported yet |
| 16 | if (deleted): |
| 17 | return [] |
| 18 | |
Tony Mack | 04054f5 | 2013-10-14 17:15:57 -0400 | [diff] [blame] | 19 | site_roles = SiteRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
Tony Mack | 03742a7 | 2013-10-08 14:42:21 -0400 | [diff] [blame] | 20 | slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 21 | controller_roles = ControllerRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
Tony Mack | 27c7390 | 2013-10-08 14:36:33 -0400 | [diff] [blame] | 22 | |
| 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 Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 28 | for controller_role in controller_roles: |
| 29 | roles.append(controller_role) |
Tony Mack | 27c7390 | 2013-10-08 14:36:33 -0400 | [diff] [blame] | 30 | |
| 31 | return roles |
| 32 | |
| 33 | |
| 34 | def sync_record(self, role): |
Tony Mack | 0fef227 | 2014-04-15 12:13:42 -0400 | [diff] [blame] | 35 | if not role.enacted: |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 36 | controllers = Controller.objects.all() |
| 37 | for controller in controllers: |
Sapan Bhatia | be623d2 | 2014-12-22 01:41:28 -0500 | [diff] [blame] | 38 | driver = self.driver.admin_driver(controller=controller) |
Tony Mack | 0fef227 | 2014-04-15 12:13:42 -0400 | [diff] [blame] | 39 | driver.create_role(role.role) |
Scott Baker | 3949bc6 | 2014-05-12 10:42:16 -0700 | [diff] [blame] | 40 | role.save() |
| 41 | |