add destroy tool
diff --git a/xos/tosca/destroy.py b/xos/tosca/destroy.py
new file mode 100644
index 0000000..fd86fdc
--- /dev/null
+++ b/xos/tosca/destroy.py
@@ -0,0 +1,31 @@
+import os
+import sys
+
+# add the parent directory to sys.path
+import os,sys,inspect
+currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
+parentdir = os.path.dirname(currentdir)
+sys.path.append(parentdir)
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
+import django
+django.setup()
+
+from core.models import User
+from tosca.engine import XOSTosca
+
+def main():
+ if len(sys.argv)<3:
+ print "Syntax: destroy.py <username> <yaml-template-name>"
+ sys.exit(-1)
+
+ username = sys.argv[1]
+ template_name = sys.argv[2]
+
+ u = User.objects.get(email=username)
+
+ xt = XOSTosca(file(template_name).read(), parent_dir=currentdir)
+ xt.destroy(u)
+
+if __name__=="__main__":
+ main()
diff --git a/xos/tosca/engine.py b/xos/tosca/engine.py
index 118bfe2..a01ddd6 100644
--- a/xos/tosca/engine.py
+++ b/xos/tosca/engine.py
@@ -41,8 +41,22 @@
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):
+ models = []
+ for nodetemplate in self.template.nodetemplates:
+ if nodetemplate.type in resources.resources:
+ cls = resources.resources[nodetemplate.type]
+ obj = cls(user, nodetemplate)
+ models = models + list(obj.get_existing_objs())
+ models.reverse()
+ for model in models:
+ print "destroying", model
+ model.delete(purge=True) # XXX change before deploying
diff --git a/xos/tosca/resources/slice.py b/xos/tosca/resources/slice.py
index 90ae75f..7e63ba0 100644
--- a/xos/tosca/resources/slice.py
+++ b/xos/tosca/resources/slice.py
@@ -13,9 +13,6 @@
provides = "tosca.nodes.Slice"
xos_model = Slice
- def get_existing_objs(self):
- return Slice.objects.filter(name=self.nodetemplate.name)
-
def get_xos_args(self):
site_name = self.get_requirement("tosca.relationships.MemberOfSite", throw_exception=True)
site = self.get_xos_object(Site, login_base=site_name)