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 | 91463d9 | 2014-06-19 20:42:03 -0400 | [diff] [blame^] | 7 | from core.models.site import SiteRole, Deployment, DeploymentRole |
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 | |
| 14 | def fetch_pending(self): |
Tony Mack | 04054f5 | 2013-10-14 17:15:57 -0400 | [diff] [blame] | 15 | 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] | 16 | slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
Tony Mack | f4f1616 | 2013-10-08 15:30:35 -0400 | [diff] [blame] | 17 | deployment_roles = DeploymentRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
Tony Mack | 27c7390 | 2013-10-08 14:36:33 -0400 | [diff] [blame] | 18 | |
| 19 | roles = [] |
| 20 | for site_role in site_roles: |
| 21 | roles.append(site_role) |
| 22 | for slice_role in slice_roles: |
| 23 | roles.append(slice_role) |
Tony Mack | f4f1616 | 2013-10-08 15:30:35 -0400 | [diff] [blame] | 24 | for deployment_role in deployment_roles: |
| 25 | roles.append(deployment_role) |
Tony Mack | 27c7390 | 2013-10-08 14:36:33 -0400 | [diff] [blame] | 26 | |
| 27 | return roles |
| 28 | |
| 29 | |
| 30 | def sync_record(self, role): |
Tony Mack | 0fef227 | 2014-04-15 12:13:42 -0400 | [diff] [blame] | 31 | if not role.enacted: |
| 32 | deployments = Deployment.objects.all() |
Scott Baker | 3949bc6 | 2014-05-12 10:42:16 -0700 | [diff] [blame] | 33 | for deployment in deployments: |
Tony Mack | 0fef227 | 2014-04-15 12:13:42 -0400 | [diff] [blame] | 34 | driver = self.driver.admin_driver(deployment=deployment.name) |
| 35 | driver.create_role(role.role) |
Scott Baker | 3949bc6 | 2014-05-12 10:42:16 -0700 | [diff] [blame] | 36 | role.save() |
| 37 | |