Matteo Scandolo | f5e1033 | 2017-08-08 13:05:25 -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 | |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 17 | import os |
| 18 | import base64 |
| 19 | from collections import defaultdict |
| 20 | from django.db.models import F, Q |
| 21 | from xos.config import Config |
| 22 | from synchronizers.base.syncstep import * |
| 23 | from core.models.site import Controller, SiteDeployment, SiteDeployment |
| 24 | from core.models.user import User |
| 25 | from core.models.controlleruser import ControllerUser |
Sapan Bhatia | b8e981d | 2017-01-24 19:32:59 +0100 | [diff] [blame] | 26 | from synchronizers.base.ansible_helper import * |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 27 | from xos.logger import observer_logger as logger |
| 28 | import json |
| 29 | |
| 30 | class SyncControllerUsers(SyncStep): |
| 31 | provides=[User] |
| 32 | requested_interval=0 |
| 33 | observes=ControllerUser |
| 34 | playbook='sync_controller_users.yaml' |
| 35 | |
| 36 | def map_sync_inputs(self, controller_user): |
| 37 | if not controller_user.controller.admin_user: |
| 38 | logger.info("controller %r has no admin_user, skipping" % controller_user.controller) |
| 39 | return |
| 40 | |
| 41 | if not controller_user.user.site: |
| 42 | raise Exception('Siteless user %s'%controller_user.user.email) |
| 43 | |
| 44 | if controller_user.user.email == controller_user.controller.admin_user: |
| 45 | logger.info("user %s is the admin_user at controller %r, skipping" % (controller_user.user.email, controller_user.controller)) |
| 46 | return |
| 47 | |
| 48 | user_fields = { |
| 49 | 'endpoint':controller_user.controller.auth_url, |
| 50 | 'name': controller_user.user.email, |
| 51 | 'firstname': controller_user.user.firstname, |
| 52 | 'lastname': controller_user.user.lastname, |
| 53 | 'phone': controller_user.user.phone, |
| 54 | 'user_url': controller_user.user.user_url, |
| 55 | 'public_key': controller_user.user.public_key, |
| 56 | 'is_active': controller_user.user.is_active, |
| 57 | 'is_admin': controller_user.user.is_admin, |
| 58 | 'is_readonly': controller_user.user.is_readonly, |
| 59 | 'is_appuser': controller_user.user.is_appuser, |
| 60 | 'password': controller_user.user.remote_password, |
| 61 | 'admin_user': controller_user.controller.admin_user, |
| 62 | 'admin_password': controller_user.controller.admin_password, |
| 63 | 'ansible_tag':'%s@%s'%(controller_user.user.email.replace('@','-at-'),controller_user.controller.name), |
| 64 | } |
| 65 | return user_fields |
| 66 | |
| 67 | def map_sync_outputs(self, controller_user, res): |
| 68 | #controller_user.kuser_id = res[0]['user']['id'] |
| 69 | controller_user.kuser_id = 'not implemented' |
| 70 | controller_user.backend_status = '1 - OK' |
| 71 | controller_user.save() |
| 72 | |
| 73 | def delete_record(self, controller_user): |
| 74 | """ |
| 75 | if controller_user.kuser_id: |
| 76 | driver = self.driver.admin_driver(controller=controller_user.controller) |
| 77 | driver.delete_user(controller_user.kuser_id) |
| 78 | """ |
| 79 | pass |