From: Tony Mack Date: Wed, 26 Jun 2013 15:28:57 +0000 (-0400) Subject: delete_tenant() deletes all instances associated with the specified tenant X-Git-Tag: 1.0~8^2~7 X-Git-Url: http://git.onelab.eu/?p=plstackapi.git;a=commitdiff_plain;h=ac3e014b8c3c2fe436d25514d92e81537e9587de delete_tenant() deletes all instances associated with the specified tenant --- diff --git a/planetstack/openstack/driver.py b/planetstack/openstack/driver.py index 4c0791e..b9faa97 100644 --- a/planetstack/openstack/driver.py +++ b/planetstack/openstack/driver.py @@ -51,8 +51,17 @@ class OpenStackDriver: return self.shell.keystone.tenants.update(id, **kwds) def delete_tenant(self, id): + ctx = self.shell.nova_db.ctx tenants = self.shell.keystone.tenants.findall(id=id) for tenant in tenants: + # nova does not automatically delete the tenant's instances + # so we manually delete instances before deleteing the tenant + instances = self.shell.nova_db.instance_get_all_by_filters(ctx, + {'project_id': tenant.id}, 'id', 'asc') + client = OpenStackClient(tenant=tenant) + driver = OpenStackDriver(client=client) + for instance in instances: + driver.destroy_instance(instance.id) self.shell.keystone.tenants.delete(tenant) return 1