Matteo Scandolo | f044103 | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 17 | import os |
| 18 | import base64 |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 19 | from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 20 | from synchronizers.new_base.syncstep import * |
| 21 | from synchronizers.new_base.ansible_helper import * |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 22 | import json |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 23 | from synchronizers.new_base.modelaccessor import * |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 24 | |
| 25 | class SyncControllerSites(OpenStackSyncStep): |
| 26 | requested_interval=0 |
| 27 | provides=[Site] |
| 28 | observes=ControllerSite |
| 29 | playbook = 'sync_controller_sites.yaml' |
| 30 | |
| 31 | def fetch_pending(self, deleted=False): |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 32 | lobjs = super(SyncControllerSites, self).fetch_pending(deleted) |
| 33 | |
| 34 | if not deleted: |
| 35 | # filter out objects with null controllers |
| 36 | lobjs = [x for x in lobjs if x.controller] |
| 37 | |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 38 | return lobjs |
| 39 | |
| 40 | def map_sync_inputs(self, controller_site): |
| 41 | tenant_fields = {'endpoint':controller_site.controller.auth_url, |
Zack Williams | 9cb1f3a | 2017-08-20 19:35:03 -0700 | [diff] [blame] | 42 | 'endpoint_v3': controller_site.controller.auth_url_v3, |
| 43 | 'domain': controller_site.controller.domain, |
| 44 | 'admin_user': controller_site.controller.admin_user, |
| 45 | 'admin_password': controller_site.controller.admin_password, |
| 46 | 'admin_tenant': controller_site.controller.admin_tenant, |
| 47 | 'admin_project': 'admin', |
| 48 | 'ansible_tag': '%s@%s'%(controller_site.site.login_base,controller_site.controller.name), # name of ansible playbook |
| 49 | 'project': controller_site.site.login_base, |
| 50 | 'project_description': controller_site.site.name} |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 51 | return tenant_fields |
| 52 | |
| 53 | def map_sync_outputs(self, controller_site, res): |
Zack Williams | 2b1f7f8 | 2017-08-28 11:45:55 -0700 | [diff] [blame] | 54 | controller_site.tenant_id = res[0]['project']['id'] |
Sapan Bhatia | b9e504c | 2017-08-29 18:39:53 -0400 | [diff] [blame] | 55 | controller_site.backend_status = 'OK' |
| 56 | controller_site.backend_code = 1 |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 57 | controller_site.save() |
Zack Williams | 9cb1f3a | 2017-08-20 19:35:03 -0700 | [diff] [blame] | 58 | |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 59 | def delete_record(self, controller_site): |
| 60 | controller_register = json.loads(controller_site.controller.backend_register) |
| 61 | if (controller_register.get('disabled',False)): |
| 62 | raise InnocuousException('Controller %s is disabled'%controller_site.controller.name) |
| 63 | |
| 64 | if controller_site.tenant_id: |
| 65 | driver = self.driver.admin_driver(controller=controller_site.controller) |
| 66 | driver.delete_tenant(controller_site.tenant_id) |
| 67 | |
| 68 | """ |
| 69 | Ansible does not support tenant deletion yet |
| 70 | |
| 71 | import pdb |
| 72 | pdb.set_trace() |
| 73 | template = os_template_env.get_template('delete_controller_sites.yaml') |
| 74 | tenant_fields = {'endpoint':controller_site.controller.auth_url, |
| 75 | 'admin_user': controller_site.controller.admin_user, |
| 76 | 'admin_password': controller_site.controller.admin_password, |
| 77 | 'admin_tenant': 'admin', |
| 78 | 'ansible_tag': 'controller_sites/%s@%s'%(controller_site.controller_site.site.login_base,controller_site.controller_site.deployment.name), # name of ansible playbook |
| 79 | 'tenant': controller_site.controller_site.site.login_base, |
| 80 | 'delete': True} |
| 81 | |
| 82 | rendered = template.render(tenant_fields) |
| 83 | res = run_template('sync_controller_sites.yaml', tenant_fields) |
| 84 | |
| 85 | if (len(res)!=1): |
| 86 | raise Exception('Could not assign roles for user %s'%tenant_fields['tenant']) |
| 87 | """ |