refactor pre_delete as can_delete
diff --git a/xos/tosca/resources/service.py b/xos/tosca/resources/service.py
index c331789..01aee1c 100644
--- a/xos/tosca/resources/service.py
+++ b/xos/tosca/resources/service.py
@@ -28,8 +28,9 @@
self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service)))
- def pre_delete(self, obj):
+ def can_delete(self, obj):
if obj.slices.exists():
self.info("Service %s has active slices; skipping delete" % obj.name)
- return
+ return False
+ return super(XOSService, self).can_delete(obj)
diff --git a/xos/tosca/resources/xosresource.py b/xos/tosca/resources/xosresource.py
index e848ab5..7599a5f 100644
--- a/xos/tosca/resources/xosresource.py
+++ b/xos/tosca/resources/xosresource.py
@@ -61,7 +61,7 @@
return objs[0]
def get_existing_objs(self):
- return self.xos_model.objects.filter(name = self.nodetemplate.name)
+ return self.xos_model.objects.filter(**{self.name_field: self.nodetemplate.name})
def get_xos_args(self):
return {}
@@ -74,8 +74,8 @@
else:
self.create()
- def pre_delete(self, obj):
- pass
+ def can_delete(self, obj):
+ return True
def postprocess(self, obj):
pass
@@ -108,9 +108,9 @@
pass
def delete(self, obj):
- self.info("destroying object %s" % str(obj))
- self.pre_delete(obj)
- obj.delete(purge=True) # XXX TODO: turn off purge before production
+ if (self.can_delete(obj)):
+ self.info("destroying object %s" % str(obj))
+ obj.delete(purge=True) # XXX TODO: turn off purge before production
def info(self, s):
self.engine.log(s)