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