Permalink
Browse files

Add ex_delete_children argument to delete_entity error. If this argum…

…ent is true and Entity has any children this function will also delete all children before deleting an entity.
  • Loading branch information...
1 parent 6cf4a06 commit 2eedff5d597fa833866763c0a51ad395c3df7362 @Kami Kami committed Nov 10, 2011
Showing with 16 additions and 3 deletions.
  1. +16 −3 libcloud/monitoring/drivers/rackspace.py
View
19 libcloud/monitoring/drivers/rackspace.py
@@ -485,9 +485,22 @@ def _to_entity(self, entity, value_dict):
ips.append((key, ipaddrs[key]))
return Entity(id=entity['id'], name=entity['label'], extra=entity['metadata'], driver=self, ip_addresses = ips)
- def delete_entity(self, entity):
- resp = self.connection.request("/entities/%s" % (entity.id),
- method='DELETE')
+ def delete_entity(self, entity, ex_delete_children=False):
+ try:
+ resp = self.connection.request("/entities/%s" % (entity.id),
+ method='DELETE')
+ except RackspaceMonitoringValidationError, e:
+ type = e.details['type']
+ if not ex_delete_children or e.type != 'childrenExistError':
+ raise e
+
+ if type == 'Check':
+ self.ex_delete_checks(entity=entity)
+ elif type == 'Alarm':
+ self.ex_delete_alarms(entity=entity)
+
+ return self.delete_entity(entity=entity, ex_delete_children=True)
+
return resp.status == httplib.NO_CONTENT
def list_entities(self, ex_next_marker=None):

0 comments on commit 2eedff5

Please sign in to comment.