Sapan Bhatia | 26d40bc | 2014-05-12 15:28:02 -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 | from core.models.deployment import DeploymentRole |
| 10 | |
| 11 | class SyncRoles(OpenStackSyncStep): |
| 12 | provides=[Role] |
| 13 | requested_interval=0 |
| 14 | |
| 15 | def fetch_pending(self): |
| 16 | site_roles = SiteRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| 17 | slice_roles = SliceRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| 18 | deployment_roles = DeploymentRole.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| 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) |
| 25 | for deployment_role in deployment_roles: |
| 26 | roles.append(deployment_role) |
| 27 | |
| 28 | return roles |
| 29 | |
| 30 | |
| 31 | def sync_record(self, role): |
| 32 | if not role.enacted: |
| 33 | deployments = Deployment.objects.all() |
| 34 | for deployment in deployments: |
| 35 | driver = self.driver.admin_driver(deployment=deployment.name) |
| 36 | driver.create_role(role.role) |
| 37 | role.save() |