only delete slices and slivers if they are empty
diff --git a/xos/tosca/engine.py b/xos/tosca/engine.py
index b5ce94b..0801c9b 100644
--- a/xos/tosca/engine.py
+++ b/xos/tosca/engine.py
@@ -105,7 +105,7 @@
return order + noorder
def execute(self, user):
- for nodetemplate in self.ordered_nodetemplates: # self.template.nodetemplates:
+ for nodetemplate in self.ordered_nodetemplates:
self.execute_nodetemplate(user, nodetemplate)
def execute_nodetemplate(self, user, nodetemplate):
@@ -115,13 +115,6 @@
obj = cls(user, nodetemplate)
obj.create_or_update()
- def execute_nodetemplate(self, user, nodetemplate):
- if nodetemplate.type in resources.resources:
- cls = resources.resources[nodetemplate.type]
- print "work on", cls.__name__, nodetemplate.name
- obj = cls(user, nodetemplate)
- obj.create_or_update()
-
def destroy(self, user):
nodetemplates = self.ordered_nodetemplates
models = []
@@ -129,9 +122,10 @@
if nodetemplate.type in resources.resources:
cls = resources.resources[nodetemplate.type]
obj = cls(user, nodetemplate)
- models = models + list(obj.get_existing_objs())
+ for model in obj.get_existing_objs():
+ models.append( (obj, model) )
models.reverse()
- for model in models:
+ for (resource,model) in models:
print "destroying", model
- model.delete(purge=True) # XXX change before deploying
+ resource.delete(model)
diff --git a/xos/tosca/resources/service.py b/xos/tosca/resources/service.py
index fb394e4..12b0464 100644
--- a/xos/tosca/resources/service.py
+++ b/xos/tosca/resources/service.py
@@ -42,3 +42,9 @@
self.info("Created Service '%s'" % (str(service), ))
+ def delete(self, obj):
+ if obj.slices.exists():
+ self.info("Service %s has active slices; skipping delete" % obj.name)
+ return
+ obj.delete()
+
diff --git a/xos/tosca/resources/slice.py b/xos/tosca/resources/slice.py
index 7e63ba0..7ac45f7 100644
--- a/xos/tosca/resources/slice.py
+++ b/xos/tosca/resources/slice.py
@@ -30,4 +30,11 @@
self.info("Created Slice '%s' on Site '%s'" % (str(slice), str(slice.site)))
+ def delete(self, obj):
+ if obj.slivers.exists():
+ self.info("Slice %s has active slivers; skipping delete" % obj.name)
+ return
+ super(XOSSlice, self).delete(obj)
+
+
diff --git a/xos/tosca/resources/xosresource.py b/xos/tosca/resources/xosresource.py
index 573c167..04ee4aa 100644
--- a/xos/tosca/resources/xosresource.py
+++ b/xos/tosca/resources/xosresource.py
@@ -74,6 +74,9 @@
def update(self, obj):
pass
+ def delete(self, obj):
+ obj.delete(purge=True) # XXX TODO: turn off purge before production
+
def info(self, s):
print s