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 | |
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 | f4f1616 | 2013-10-08 15:30:35 -0400 | [diff] [blame] | 21 | 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] | 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 | f4f1616 | 2013-10-08 15:30:35 -0400 | [diff] [blame] | 28 | for deployment_role in deployment_roles: |
| 29 | roles.append(deployment_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: |
| 36 | deployments = Deployment.objects.all() |
Scott Baker | 3949bc6 | 2014-05-12 10:42:16 -0700 | [diff] [blame] | 37 | for deployment in deployments: |
Tony Mack | 0fef227 | 2014-04-15 12:13:42 -0400 | [diff] [blame] | 38 | driver = self.driver.admin_driver(deployment=deployment.name) |
| 39 | driver.create_role(role.role) |
Scott Baker | 3949bc6 | 2014-05-12 10:42:16 -0700 | [diff] [blame] | 40 | role.save() |
| 41 | |