Added delete for non-sync'd objects. Resolves #9 and #82
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)