Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/planetstack/core/models/user.py b/planetstack/core/models/user.py
index b30e897..fb0d232 100644
--- a/planetstack/core/models/user.py
+++ b/planetstack/core/models/user.py
@@ -1,6 +1,7 @@
 import os
 import datetime
 import sys
+import hashlib
 from collections import defaultdict
 from django.forms.models import model_to_dict
 from django.db import models
@@ -113,6 +114,10 @@
         return self.diff.get(field_name, None)
     # ---- end copy stuff from DiffModelMixin ----
 
+    @property
+    def remote_password(self):
+        return hashlib.md5(self.password).hexdigest()[:12]
+
     class Meta:
         app_label = "core"
 
diff --git a/planetstack/openstack_observer/steps/sync_controller_images.py b/planetstack/openstack_observer/steps/sync_controller_images.py
index 0a0910e..008de71 100644
--- a/planetstack/openstack_observer/steps/sync_controller_images.py
+++ b/planetstack/openstack_observer/steps/sync_controller_images.py
@@ -24,9 +24,6 @@
 
     def sync_record(self, controller_image):
         logger.info("Working on image %s on controller %s" % (controller_image.image.name, controller_image.controller))
-        import pdb
-        pdb.set_trace()
-
 	image_fields = {'endpoint':controller_image.controller.auth_url,
 			'admin_user':controller_image.controller.admin_user,
 			'admin_password':controller_image.controller.admin_password,
diff --git a/planetstack/openstack_observer/steps/sync_controller_slices.py b/planetstack/openstack_observer/steps/sync_controller_slices.py
index c6021ba..b1a1f55 100644
--- a/planetstack/openstack_observer/steps/sync_controller_slices.py
+++ b/planetstack/openstack_observer/steps/sync_controller_slices.py
@@ -9,7 +9,6 @@
 from core.models.controllerusers import ControllerUsers
 from util.logger import Logger, logging
 from observer.ansible import *
-import pdb
 
 logger = Logger(level=logging.INFO)
 
@@ -38,7 +37,6 @@
             controller_user = controller_users[0]
             roles = ['admin']
 
-        pdb.set_trace()
         max_instances=int(controller_slice.slice.max_slivers)
         tenant_fields = {'endpoint':controller_slice.controller.auth_url,
                          'admin_user': controller_slice.controller.admin_user,
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:
diff --git a/planetstack/openstack_observer/steps/sync_slivers.py b/planetstack/openstack_observer/steps/sync_slivers.py
index 6855785..94fd0d5 100644
--- a/planetstack/openstack_observer/steps/sync_slivers.py
+++ b/planetstack/openstack_observer/steps/sync_slivers.py
@@ -8,7 +8,6 @@
 from core.models.network import Network, NetworkSlice, ControllerNetworks
 from util.logger import Logger, logging
 from observer.ansible import *
-import pdb
 
 logger = Logger(level=logging.INFO)