Merge branch 'master' of github.com:open-cloud/xos
diff --git a/xos/core/models/plcorebase.py b/xos/core/models/plcorebase.py
index 5e3e287..3eaf7e6 100644
--- a/xos/core/models/plcorebase.py
+++ b/xos/core/models/plcorebase.py
@@ -119,11 +119,12 @@
         return validators
 
     def get_backend_icon(self):
+        is_perfect = (self.backend_status is not None) and self.backend_status.startswith("1 -")
         is_good = (self.backend_status is not None) and (self.backend_status.startswith("0 -") or self.backend_status.startswith("1 -"))
         is_provisioning = self.backend_status is None or self.backend_status == "Provisioning in progress" or self.backend_status==""
 
         # returns (icon_name, tooltip)
-        if (self.enacted is not None) and self.enacted >= self.updated and is_good:
+        if (self.enacted is not None) and (self.enacted >= self.updated and is_good) or is_perfect:
             return ("success", "successfully enacted")
         else:
             if is_good or is_provisioning:
diff --git a/xos/dependency_walker.py b/xos/dependency_walker.py
index ba9de11..d99b783 100644
--- a/xos/dependency_walker.py
+++ b/xos/dependency_walker.py
@@ -46,7 +46,7 @@
 		deps = dependencies[model]
 	except:
 		deps = []
-	__walk_deps(fn, object, deps)
+	return __walk_deps(fn, object, deps)
 
 def walk_inv_deps(fn, object):
 	model = object.__class__.__name__
@@ -54,10 +54,11 @@
 		deps = inv_dependencies[model]
 	except:
 		deps = []
-	__walk_deps(fn, object, deps)
+	return __walk_deps(fn, object, deps)
 
 def __walk_deps(fn, object, deps):
 	model = object.__class__.__name__
+	ret = []
 	for dep in deps:
 		#print "Checking dep %s"%dep
 		peer=None
@@ -87,8 +88,10 @@
 				#if (isinstance(o,PlCoreBase)):
 				if (hasattr(o,'updated')):
 					fn(o, object)
+					ret.append(o)
 				# Uncomment the following line to enable recursion
 				# walk_inv_deps(fn, o)
+	return ret
 
 def p(x,source):
 	print x,x.__class__.__name__
@@ -96,11 +99,9 @@
 
 def main():
 	#pdb.set_trace()
-	import django
-	django.setup()
-	s = Site.objects.filter(login_base='onlab')
+	s = Slice.objects.filter(name='princeton_sapan62')
 	#pdb.set_trace()
-	walk_inv_deps(p,s[0])
+	print walk_inv_deps(p,s[0])
 	
 if __name__=='__main__':
 	main()
diff --git a/xos/model_policy.py b/xos/model_policy.py
index 9333adc..19c281a 100644
--- a/xos/model_policy.py
+++ b/xos/model_policy.py
@@ -90,6 +90,9 @@
         logging.error('Object %r is defective'%instance)
         bad_instances.append(instance)
 
+def noop(o,p):
+        pass
+
 def run_policy():
     from core.models import Sliver,Slice,Controller,Network,User,SlicePrivilege,Site,SitePrivilege,Image,ControllerSlice,ControllerUser,ControllerSite
     while (True):
@@ -110,6 +113,16 @@
         for o in deleted_objects:
             execute_model_policy(o, True)
 
+        # Reap non-sync'd models here
+        reaped = [Slice]
+
+        for m in reaped:
+            dobjs = m.deleted_objects.all()
+            for d in dobjs:
+                deps = walk_inv_deps(noop, d)
+                if (not deps):
+                    print 'Purging object %r'%d
+                    d.delete(purge=True)
 
         if (time.time()-start<1):
             time.sleep(1)