blob: 9316425bda73398864f314da99709113e1095913 [file] [log] [blame]
Tony Mack06c8e472014-11-30 15:53:08 -05001import os
2import base64
3from django.db.models import F, Q
4from planetstack.config import Config
5from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.site import *
7from observer.ansible import *
8
Tony Mackd14d48f2014-12-05 17:13:08 -05009class SyncControllerSiteDeployments(OpenStackSyncStep):
Tony Mack06c8e472014-11-30 15:53:08 -050010 requested_interval=0
11 provides=[ControllerSiteDeployments, SiteDeployments]
12
13 def sync_record(self, controller_site_deployment):
14
15 template = os_template_env.get_template('sync_controller_site_deployments.yaml')
16 tenant_fields = {'endpoint':controller_site_deployment.controller.auth_url,
17 'admin_user': controller_site_deployment.controller.admin_user,
18 'admin_password': controller_site_deployment.controller.admin_password,
19 'admin_tenant': 'admin',
Sapan Bhatia963831e2014-12-21 02:33:52 -050020 'ansible_tag': '%s@%s'%(controller_site_deployment.site_deployment.site.login_base,controller_site_deployment.site_deployment.deployment.name), # name of ansible playbook
Tony Mack06c8e472014-11-30 15:53:08 -050021 'tenant': controller_site_deployment.site_deployment.site.login_base,
22 'tenant_description': controller_site_deployment.site_deployment.site.name}
23
24 rendered = template.render(tenant_fields)
Sapan Bhatia963831e2014-12-21 02:33:52 -050025 res = run_template('sync_controller_site_deployments.yaml', tenant_fields, path='site_deployments')
Tony Mack06c8e472014-11-30 15:53:08 -050026
27 if (len(res)==1):
28 controller_site_deployment.tenant_id = res[0]['id']
29 controller_site_deployment.save()
30 elif (len(res)):
31 raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
32 else:
33 raise Exception('Could not create or update user %s'%tenant_fields['tenant'])
34
35 def delete_record(self, controller_site_deployment):
Sapan Bhatia963831e2014-12-21 02:33:52 -050036 import pdb
37 pdb.set_trace()
38 if controller_site_deployment.tenant_id:
Tony Mack06c8e472014-11-30 15:53:08 -050039 driver = self.driver.admin_driver(controller=controller_site_deployment.controller)
40 driver.delete_tenant(controller_site_deployment.tenant_id)
Sapan Bhatia963831e2014-12-21 02:33:52 -050041
42 """
43 Ansible does not support tenant deletion yet
44
45 import pdb
46 pdb.set_trace()
47 template = os_template_env.get_template('delete_controller_site_deployments.yaml')
48 tenant_fields = {'endpoint':controller_site_deployment.controller.auth_url,
49 'admin_user': controller_site_deployment.controller.admin_user,
50 'admin_password': controller_site_deployment.controller.admin_password,
51 'admin_tenant': 'admin',
52 'ansible_tag': 'site_deployments/%s@%s'%(controller_site_deployment.site_deployment.site.login_base,controller_site_deployment.site_deployment.deployment.name), # name of ansible playbook
53 'tenant': controller_site_deployment.site_deployment.site.login_base,
54 'delete': True}
55
56 rendered = template.render(tenant_fields)
57 res = run_template('sync_controller_site_deployments.yaml', tenant_fields)
58
59 if (len(res)!=1):
60 raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
61 """