blob: 3aa20d731e0eb71581f3958edc3c85933b9f1733 [file] [log] [blame]
Tony Mack3066a952015-01-05 22:48:11 -05001import os
2import base64
3from django.db.models import F, Q
4from planetstack.config import Config
Tony Macke2363c12015-01-06 15:08:20 -05005from openstack_observer.openstacksyncstep import OpenStackSyncStep
Tony Mack3066a952015-01-05 22:48:11 -05006from core.models.site import *
7from observer.ansible import *
8
Tony Macke2363c12015-01-06 15:08:20 -05009class SyncControllerSites(OpenStackSyncStep):
Tony Mack3066a952015-01-05 22:48:11 -050010 requested_interval=0
Sapan Bhatiaaa98e712015-01-16 22:15:15 +000011 provides=[ControllerSite, Site]
Tony Mack3066a952015-01-05 22:48:11 -050012
13 def fetch_pending(self, deleted=False):
14 pending = super(OpenStackSyncStep, self).fetch_pending(deleted)
15 return pending.filter(controller__isnull=False)
16
17 def sync_record(self, controller_site):
18
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 Macke2363c12015-01-06 15:08:20 -050024 'ansible_tag': '%s@%s'%(controller_site.site.login_base,controller_site.controller.name), # name of ansible playbook
Tony Mack3066a952015-01-05 22:48:11 -050025 'tenant': controller_site.site.login_base,
26 'tenant_description': controller_site.site.name}
27
28 rendered = template.render(tenant_fields)
Sapan Bhatia3b3e1e12015-01-23 16:21:57 +000029 res = run_template('sync_controller_sites.yaml', tenant_fields, path='controller_sites', expected_num=1)
Tony Mack3066a952015-01-05 22:48:11 -050030
Sapan Bhatia3b3e1e12015-01-23 16:21:57 +000031 controller_site.tenant_id = res[0]['id']
32 controller_site.save()
Tony Mack3066a952015-01-05 22:48:11 -050033
34 def delete_record(self, controller_site):
35 if controller_site.tenant_id:
36 driver = self.driver.admin_driver(controller=controller_site.controller)
37 driver.delete_tenant(controller_site.tenant_id)
38
39 """
40 Ansible does not support tenant deletion yet
41
42 import pdb
43 pdb.set_trace()
44 template = os_template_env.get_template('delete_controller_sites.yaml')
45 tenant_fields = {'endpoint':controller_site.controller.auth_url,
46 'admin_user': controller_site.controller.admin_user,
47 'admin_password': controller_site.controller.admin_password,
48 'admin_tenant': 'admin',
49 'ansible_tag': 'controller_sites/%s@%s'%(controller_site.controller_site.site.login_base,controller_site.controller_site.deployment.name), # name of ansible playbook
50 'tenant': controller_site.controller_site.site.login_base,
51 'delete': True}
52
53 rendered = template.render(tenant_fields)
54 res = run_template('sync_controller_sites.yaml', tenant_fields)
55
56 if (len(res)!=1):
57 raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
58 """