blob: 78f2d8057faa873c68428de5a00f61e67820823e [file] [log] [blame]
Matteo Scandolof0441032017-08-08 13:05:26 -07001
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 Bakerb63ea792016-08-11 10:24:48 -070017import os
18import base64
Scott Bakerc808c672019-02-04 11:38:20 -080019from openstacksyncstep import OpenStackSyncStep
20from xossynchronizer.modelaccessor import *
21from xosconfig import Config
22from multistructlog import create_logger
23
24log = create_logger(Config().get('logging'))
Scott Bakerb63ea792016-08-11 10:24:48 -070025
26class SyncControllerUsers(OpenStackSyncStep):
27 provides=[User]
28 requested_interval=0
29 observes=ControllerUser
30 playbook='sync_controller_users.yaml'
31
32 def map_sync_inputs(self, controller_user):
33 if not controller_user.controller.admin_user:
Scott Bakerc808c672019-02-04 11:38:20 -080034 log.info("controller %r has no admin_user, skipping" % controller_user.controller)
Scott Bakerb63ea792016-08-11 10:24:48 -070035 return
36
37 # All users will have at least the 'user' role at their home site/tenant.
38 # We must also check if the user should have the admin role
39
40 roles = ['user']
41 if controller_user.user.is_admin:
Scott Baker04a37f52016-08-11 10:52:21 -070042 driver = self.driver.admin_driver(controller=controller_user.controller)
Scott Bakerb63ea792016-08-11 10:24:48 -070043 roles.append(driver.get_admin_role().name)
44
45 # setup user home site roles at controller
46 if not controller_user.user.site:
47 raise Exception('Siteless user %s'%controller_user.user.email)
48 else:
Scott Bakerb63ea792016-08-11 10:24:48 -070049 user_fields = {
50 'endpoint':controller_user.controller.auth_url,
51 'endpoint_v3': controller_user.controller.auth_url_v3,
52 'domain': controller_user.controller.domain,
53 'name': controller_user.user.email,
54 'email': controller_user.user.email,
55 'password': controller_user.user.remote_password,
56 'admin_user': controller_user.controller.admin_user,
57 'admin_password': controller_user.controller.admin_password,
58 'ansible_tag':'%s@%s'%(controller_user.user.email.replace('@','-at-'),controller_user.controller.name),
59 'admin_project': controller_user.controller.admin_tenant,
60 'roles':roles,
61 'project':controller_user.user.site.login_base
62 }
63 return user_fields
64
65 def map_sync_outputs(self, controller_user, res):
66 controller_user.kuser_id = res[0]['user']['id']
Sapan Bhatiab9e504c2017-08-29 18:39:53 -040067 controller_user.backend_status = 'OK'
68 controller_user.backend_code = 1
Scott Bakerb63ea792016-08-11 10:24:48 -070069 controller_user.save()
70
71 def delete_record(self, controller_user):
72 if controller_user.kuser_id:
73 driver = self.driver.admin_driver(controller=controller_user.controller)
74 driver.delete_user(controller_user.kuser_id)