step to purge disabled user records after 1 week
diff --git a/xos/openstack_observer/steps/purge_disabled_users.py b/xos/openstack_observer/steps/purge_disabled_users.py
new file mode 100644
index 0000000..9e30708
--- /dev/null
+++ b/xos/openstack_observer/steps/purge_disabled_users.py
@@ -0,0 +1,24 @@
+import os
+import base64
+import datetime
+from django.db.models import F, Q
+from xos.config import Config
+from observer.openstacksyncstep import OpenStackSyncStep
+from core.models.user import User
+from util.logger import observer_logger as logger
+
+class SyncRoles(OpenStackSyncStep):
+ provides=[User]
+ requested_interval=0
+ observes=User
+
+ def fetch_pending(self, deleted):
+ if (deleted):
+ # users marked as deleted
+ return User.deleted_objects.all()
+ else:
+ # disabled users that haven't been updated in over a week
+ one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
+ return User.objects.filter(is_active=False, updated__gt=one_week_ago)
+ def sync_record(self, user):
+ user.delete()