Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from django.db.models import F, Q |
| 4 | from planetstack.config import Config |
Tony Mack | e2363c1 | 2015-01-06 15:08:20 -0500 | [diff] [blame] | 5 | from openstack_observer.openstacksyncstep import OpenStackSyncStep |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 6 | from core.models.site import * |
| 7 | from observer.ansible import * |
| 8 | |
Tony Mack | e2363c1 | 2015-01-06 15:08:20 -0500 | [diff] [blame] | 9 | class SyncControllerSites(OpenStackSyncStep): |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 10 | requested_interval=0 |
Sapan Bhatia | 5d662c7 | 2015-01-27 03:52:19 +0000 | [diff] [blame] | 11 | provides=[Site] |
Sapan Bhatia | 39a775f | 2015-01-29 20:58:25 +0000 | [diff] [blame] | 12 | observes=ControllerSite |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 13 | |
| 14 | def fetch_pending(self, deleted=False): |
| 15 | pending = super(OpenStackSyncStep, self).fetch_pending(deleted) |
| 16 | return pending.filter(controller__isnull=False) |
| 17 | |
| 18 | def sync_record(self, controller_site): |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 19 | template = os_template_env.get_template('sync_controller_sites.yaml') |
| 20 | tenant_fields = {'endpoint':controller_site.controller.auth_url, |
| 21 | 'admin_user': controller_site.controller.admin_user, |
| 22 | 'admin_password': controller_site.controller.admin_password, |
| 23 | 'admin_tenant': controller_site.controller.admin_tenant, |
Tony Mack | e2363c1 | 2015-01-06 15:08:20 -0500 | [diff] [blame] | 24 | 'ansible_tag': '%s@%s'%(controller_site.site.login_base,controller_site.controller.name), # name of ansible playbook |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 25 | 'tenant': controller_site.site.login_base, |
| 26 | 'tenant_description': controller_site.site.name} |
| 27 | |
| 28 | rendered = template.render(tenant_fields) |
Sapan Bhatia | 3b3e1e1 | 2015-01-23 16:21:57 +0000 | [diff] [blame] | 29 | res = run_template('sync_controller_sites.yaml', tenant_fields, path='controller_sites', expected_num=1) |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 30 | |
Sapan Bhatia | 3b3e1e1 | 2015-01-23 16:21:57 +0000 | [diff] [blame] | 31 | controller_site.tenant_id = res[0]['id'] |
Sapan Bhatia | c88c9a8 | 2015-01-27 03:52:43 +0000 | [diff] [blame] | 32 | controller_site.backend_status = '1 - OK' |
Sapan Bhatia | 3b3e1e1 | 2015-01-23 16:21:57 +0000 | [diff] [blame] | 33 | controller_site.save() |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 34 | |
| 35 | def delete_record(self, controller_site): |
| 36 | if controller_site.tenant_id: |
| 37 | driver = self.driver.admin_driver(controller=controller_site.controller) |
| 38 | driver.delete_tenant(controller_site.tenant_id) |
| 39 | |
| 40 | """ |
| 41 | Ansible does not support tenant deletion yet |
| 42 | |
| 43 | import pdb |
| 44 | pdb.set_trace() |
| 45 | template = os_template_env.get_template('delete_controller_sites.yaml') |
| 46 | tenant_fields = {'endpoint':controller_site.controller.auth_url, |
| 47 | 'admin_user': controller_site.controller.admin_user, |
| 48 | 'admin_password': controller_site.controller.admin_password, |
| 49 | 'admin_tenant': 'admin', |
| 50 | 'ansible_tag': 'controller_sites/%s@%s'%(controller_site.controller_site.site.login_base,controller_site.controller_site.deployment.name), # name of ansible playbook |
| 51 | 'tenant': controller_site.controller_site.site.login_base, |
| 52 | 'delete': True} |
| 53 | |
| 54 | rendered = template.render(tenant_fields) |
| 55 | res = run_template('sync_controller_sites.yaml', tenant_fields) |
| 56 | |
| 57 | if (len(res)!=1): |
| 58 | raise Exception('Could not assign roles for user %s'%tenant_fields['tenant']) |
| 59 | """ |