refactor
diff --git a/planetstack/openstack_observer/steps/sync_controller_users.py b/planetstack/openstack_observer/steps/sync_controller_users.py
index 8f7e508..113869e 100644
--- a/planetstack/openstack_observer/steps/sync_controller_users.py
+++ b/planetstack/openstack_observer/steps/sync_controller_users.py
@@ -1,6 +1,5 @@
import os
import base64
-import hashlib
from collections import defaultdict
from django.db.models import F, Q
from planetstack.config import Config
@@ -33,57 +32,53 @@
return
template = os_template_env.get_template('sync_controller_users.yaml')
-
- name = controller_user.user.email[:controller_user.user.email.find('@')]
- import pdb
- pdb.set_trace()
+ # All users will have at least the 'user' role at their home site/tenant.
+ # We must also check if the user should have the admin role
roles = ['user']
if controller_user.user.is_admin:
roles.append('admin')
- else:
- raise Exception('Internal error. Missing controller for user %s'%controller_user.user.email)
# setup user home site roles at controller
if not controller_user.user.site:
- raise Exception('Siteless user %s'%controller_user.user.email)
+ raise Exception('Siteless user %s'%controller_user.user.email)
else:
# look up tenant id for the user's site at the controller
- ctrl_site_deployments = ControllerSiteDeployments.objects.filter(
- site_deployment__site=controller_user.user.site,
- controller=controller_user.controller)
+ #ctrl_site_deployments = ControllerSiteDeployments.objects.filter(
+ # site_deployment__site=controller_user.user.site,
+ # controller=controller_user.controller)
- if ctrl_site_deployments:
- # need the correct tenant id for site at the controller
- tenant_id = ctrl_site_deployments[0].tenant_id
- tenant_name = ctrl_site_deployments[0].site_deployment.site.login_base
-
- user_fields = {'endpoint':controller_user.controller.auth_url,
+ #if ctrl_site_deployments:
+ # # need the correct tenant id for site at the controller
+ # tenant_id = ctrl_site_deployments[0].tenant_id
+ # tenant_name = ctrl_site_deployments[0].site_deployment.site.login_base
+ user_fields = {
+ 'endpoint':controller_user.controller.auth_url,
'name': controller_user.user.email,
'email': controller_user.user.email,
- 'password': hashlib.md5(controller_user.user.password).hexdigest()[:6],
+ 'password': controller_user.user.remote_password,
'admin_user': controller_user.controller.admin_user,
'admin_password': controller_user.controller.admin_password,
'ansible_tag':'%s@%s'%(controller_user.user.email.replace('@','-at-'),controller_user.controller.name),
- 'admin_tenant': 'admin',
+ 'admin_tenant': controller_user.controller.admin_tenant,
'roles':roles,
- 'tenant':tenant_name}
+ 'tenant':controller_user.user.site.login_base}
- rendered = template.render(user_fields)
- res = run_template('sync_controller_users.yaml', user_fields,path='controller_users')
+ rendered = template.render(user_fields)
+ res = run_template('sync_controller_users.yaml', user_fields,path='controller_users')
- # results is an array in which each element corresponds to an
- # "ok" string received per operation. If we get as many oks as
- # the number of operations we issued, that means a grand success.
- # Otherwise, the number of oks tell us which operation failed.
- expected_length = len(roles) + 1
- if (len(res)==expected_length):
- controller_user.kuser_id = res[0]['id']
- controller_user.save()
- elif (len(res)):
- raise Exception('Could not assign roles for user %s'%user_fields['name'])
- else:
- raise Exception('Could not create or update user %s'%user_fields['name'])
+ # results is an array in which each element corresponds to an
+ # "ok" string received per operation. If we get as many oks as
+ # the number of operations we issued, that means a grand success.
+ # Otherwise, the number of oks tell us which operation failed.
+ expected_length = len(roles) + 1
+ if (len(res)==expected_length):
+ controller_user.kuser_id = res[0]['id']
+ controller_user.save()
+ elif (len(res)):
+ raise Exception('Could not assign roles for user %s'%user_fields['name'])
+ else:
+ raise Exception('Could not create or update user %s'%user_fields['name'])
def delete_record(self, controller_user):
if controller_user.kuser_id: