User deployments deleter refactored
diff --git a/planetstack/openstack_observer/steps/sync_user_deployments.py b/planetstack/openstack_observer/steps/sync_user_deployments.py
index a6995ab..5d6ce2d 100644
--- a/planetstack/openstack_observer/steps/sync_user_deployments.py
+++ b/planetstack/openstack_observer/steps/sync_user_deployments.py
@@ -13,46 +13,50 @@
 logger = Logger(level=logging.INFO)
 
 class SyncUserDeployments(OpenStackSyncStep):
-    provides=[User, UserDeployments]
+    provides=[UserDeployments, User]
     requested_interval=0
 
-    def fetch_pending(self):
+    def fetch_pending(self, deleted):
+
+        if (deleted):
+            return UserDeployments.deleted_objects.all()
+
         # user deployments are not visible to users. We must ensure
         # user are deployed at all deploymets available to their sites.
+        else:
+            deployments = Deployment.objects.all()
+            site_deployments = SiteDeployments.objects.all()
+            site_deploy_lookup = defaultdict(list)
+            for site_deployment in site_deployments:
+                site_deploy_lookup[site_deployment.site].append(site_deployment.deployment)
 
-        deployments = Deployment.objects.all()
-        site_deployments = SiteDeployments.objects.all()
-        site_deploy_lookup = defaultdict(list)
-        for site_deployment in site_deployments:
-            site_deploy_lookup[site_deployment.site].append(site_deployment.deployment)
+            user_deploy_lookup = defaultdict(list)
+            for user_deployment in UserDeployments.objects.all():
+                user_deploy_lookup[user_deployment.user].append(user_deployment.deployment)
+           
+            all_deployments = Deployment.objects.filter() 
+            for user in User.objects.all():
+                if user.is_admin:
+                    # admins should have an account at all deployments
+                    expected_deployments = deployments
+                else:
+                    # normal users should have an account at their site's deployments
+                    #expected_deployments = site_deploy_lookup[user.site]
+                    # users are added to all deployments for now
+                    expected_deployments = deployments        
+                for expected_deployment in expected_deployments:
+                    if not user in user_deploy_lookup or \
+                      expected_deployment not in user_deploy_lookup[user]: 
+                        # add new record
+                        ud = UserDeployments(user=user, deployment=expected_deployment)
+                        ud.save()
+                        #user_deployments.append(ud)
+                    #else:
+                    #    # update existing record
+                    #    ud = UserDeployments.objects.get(user=user, deployment=expected_deployment)
+                    #    user_deployments.append(ud)
 
-        user_deploy_lookup = defaultdict(list)
-        for user_deployment in UserDeployments.objects.all():
-            user_deploy_lookup[user_deployment.user].append(user_deployment.deployment)
-       
-        all_deployments = Deployment.objects.filter() 
-        for user in User.objects.all():
-            if user.is_admin:
-                # admins should have an account at all deployments
-                expected_deployments = deployments
-            else:
-                # normal users should have an account at their site's deployments
-                #expected_deployments = site_deploy_lookup[user.site]
-                # users are added to all deployments for now
-                expected_deployments = deployments        
-            for expected_deployment in expected_deployments:
-                if not user in user_deploy_lookup or \
-                  expected_deployment not in user_deploy_lookup[user]: 
-                    # add new record
-                    ud = UserDeployments(user=user, deployment=expected_deployment)
-                    ud.save()
-                    #user_deployments.append(ud)
-                #else:
-                #    # update existing record
-                #    ud = UserDeployments.objects.get(user=user, deployment=expected_deployment)
-                #    user_deployments.append(ud)
-
-        return UserDeployments.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) 
+            return UserDeployments.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) 
 
     def sync_record(self, user_deployment):
         logger.info("sync'ing user %s at deployment %s" % (user_deployment.user, user_deployment.deployment.name))
@@ -97,3 +101,9 @@
         #    user_driver.create_keypair(**key_fields)
 
         user_deployment.save()
+
+    def delete_record(self, user_deployment):
+        if user_deployment.user.kuser_id:
+            driver = self.driver.admin_driver(deployment=user_deployment.deployment.name)
+            driver.delete_user(user_deployment.user.kuser_id)
+