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 |
| 7 | from core.models.site import SiteRole |
| 8 | from core.models.slice import SliceRole |
| 9 | |
| 10 | class SyncRoles(OpenStackSyncStep): |
| 11 | provides=[Role] |
| 12 | requested_interval=0 |
| 13 | |
| 14 | def fetch_pending(self): |
| 15 | site_roles = SiteRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None) |
| 16 | slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated') | Q(enacted=None)) |
| 17 | |
| 18 | roles = [] |
| 19 | for site_role in site_roles: |
| 20 | roles.append(site_role) |
| 21 | for slice_role in slice_roles: |
| 22 | roles.append(slice_role) |
| 23 | |
| 24 | return roles |
| 25 | |
| 26 | |
| 27 | def sync_record(self, role): |
| 28 | save_role = False |
| 29 | if not role.krole_id: |
| 30 | krole = self.driver.create_role(role.role) |
| 31 | role.krole_id = krole.id |
| 32 | save_role = True |
| 33 | |
| 34 | if (save_role): |
| 35 | role.save() |
| 36 | |