Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from collections import defaultdict |
| 4 | from django.db.models import F, Q |
| 5 | from xos.config import Config |
| 6 | from synchronizers.base.syncstep import * |
| 7 | from core.models.site import Controller, SiteDeployment, SiteDeployment |
| 8 | from core.models.user import User |
| 9 | from core.models.controlleruser import ControllerUser |
| 10 | from synchronizers.base.ansible import * |
| 11 | from xos.logger import observer_logger as logger |
| 12 | import json |
| 13 | |
| 14 | class SyncControllerUsers(SyncStep): |
| 15 | provides=[User] |
| 16 | requested_interval=0 |
| 17 | observes=ControllerUser |
| 18 | playbook='sync_controller_users.yaml' |
| 19 | |
| 20 | def map_sync_inputs(self, controller_user): |
| 21 | if not controller_user.controller.admin_user: |
| 22 | logger.info("controller %r has no admin_user, skipping" % controller_user.controller) |
| 23 | return |
| 24 | |
| 25 | if not controller_user.user.site: |
| 26 | raise Exception('Siteless user %s'%controller_user.user.email) |
| 27 | |
| 28 | if controller_user.user.email == controller_user.controller.admin_user: |
| 29 | logger.info("user %s is the admin_user at controller %r, skipping" % (controller_user.user.email, controller_user.controller)) |
| 30 | return |
| 31 | |
| 32 | user_fields = { |
| 33 | 'endpoint':controller_user.controller.auth_url, |
| 34 | 'name': controller_user.user.email, |
| 35 | 'firstname': controller_user.user.firstname, |
| 36 | 'lastname': controller_user.user.lastname, |
| 37 | 'phone': controller_user.user.phone, |
| 38 | 'user_url': controller_user.user.user_url, |
| 39 | 'public_key': controller_user.user.public_key, |
| 40 | 'is_active': controller_user.user.is_active, |
| 41 | 'is_admin': controller_user.user.is_admin, |
| 42 | 'is_readonly': controller_user.user.is_readonly, |
| 43 | 'is_appuser': controller_user.user.is_appuser, |
| 44 | 'password': controller_user.user.remote_password, |
| 45 | 'admin_user': controller_user.controller.admin_user, |
| 46 | 'admin_password': controller_user.controller.admin_password, |
| 47 | 'ansible_tag':'%s@%s'%(controller_user.user.email.replace('@','-at-'),controller_user.controller.name), |
| 48 | } |
| 49 | return user_fields |
| 50 | |
| 51 | def map_sync_outputs(self, controller_user, res): |
| 52 | #controller_user.kuser_id = res[0]['user']['id'] |
| 53 | controller_user.kuser_id = 'not implemented' |
| 54 | controller_user.backend_status = '1 - OK' |
| 55 | controller_user.save() |
| 56 | |
| 57 | def delete_record(self, controller_user): |
| 58 | """ |
| 59 | if controller_user.kuser_id: |
| 60 | driver = self.driver.admin_driver(controller=controller_user.controller) |
| 61 | driver.delete_user(controller_user.kuser_id) |
| 62 | """ |
| 63 | pass |