blob: 881e78a4e592096e50258765bd3f0e6e344dd4ae [file] [log] [blame]
Scott Bakerbba67b62019-01-28 17:38:21 -08001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
16import os
17import base64
18from xossynchronizer.steps.syncstep import SyncStep
19from xossynchronizer.mock_modelaccessor import *
20
21
22class SyncControllerUsers(SyncStep):
23 provides = [User]
24 requested_interval = 0
25 observes = ControllerUser
26 playbook = "sync_controller_users.yaml"
27
28 def map_sync_inputs(self, controller_user):
29 if not controller_user.controller.admin_user:
30 return
31
32 # All users will have at least the 'user' role at their home site/tenant.
33 # We must also check if the user should have the admin role
34
35 roles = ["user"]
36 if controller_user.user.is_admin:
37 driver = self.driver.admin_driver(controller=controller_user.controller)
38 roles.append(driver.get_admin_role().name)
39
40 # setup user home site roles at controller
41 if not controller_user.user.site:
42 raise Exception("Siteless user %s" % controller_user.user.email)
43 else:
44 user_fields = {
45 "endpoint": controller_user.controller.auth_url,
46 "endpoint_v3": controller_user.controller.auth_url_v3,
47 "domain": controller_user.controller.domain,
48 "name": controller_user.user.email,
49 "email": controller_user.user.email,
50 "password": controller_user.user.remote_password,
51 "admin_user": controller_user.controller.admin_user,
52 "admin_password": controller_user.controller.admin_password,
53 "ansible_tag": "%s@%s"
54 % (
55 controller_user.user.email.replace("@", "-at-"),
56 controller_user.controller.name,
57 ),
58 "admin_project": controller_user.controller.admin_tenant,
59 "roles": roles,
60 "project": controller_user.user.site.login_base,
61 }
62 return user_fields
63
64 def map_sync_outputs(self, controller_user, res):
65 controller_user.kuser_id = res[0]["user"]["id"]
66 controller_user.backend_status = "1 - OK"
67 controller_user.save()
68
69 def delete_record(self, controller_user):
70 if controller_user.kuser_id:
71 driver = self.driver.admin_driver(controller=controller_user.controller)
72 driver.delete_user(controller_user.kuser_id)