Tony Mack | bdb188a | 2014-04-01 20:24:47 -0400 | [diff] [blame] | 1 | from core.models import Slice, SliceDeployments, User |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 2 | from observer.deleter import Deleter |
Sapan Bhatia | dbaf193 | 2013-09-03 11:28:52 -0400 | [diff] [blame] | 3 | |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 4 | class SliceDeleter(Deleter): |
Tony Mack | f77f140 | 2014-04-02 07:06:53 -0400 | [diff] [blame] | 5 | model='Slice' |
Sapan Bhatia | dbaf193 | 2013-09-03 11:28:52 -0400 | [diff] [blame] | 6 | |
Tony Mack | f77f140 | 2014-04-02 07:06:53 -0400 | [diff] [blame] | 7 | def call(self, pk): |
| 8 | slice = Slice.objects.get(pk=pk) |
Tony Mack | bdb188a | 2014-04-01 20:24:47 -0400 | [diff] [blame] | 9 | slice_deployments = SliceDeployments.objects.filter(slice=slice) |
| 10 | for slice_deployment in slice_deployments: |
| 11 | user = User.get(user=slice.creator) |
| 12 | driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name) |
| 13 | client_driver = self.driver.client_driver(caller=user, |
| 14 | tenant=slice.name, |
| 15 | deployment=slice_deployment.deployment.name) |
| 16 | |
| 17 | client_driver.delete_router_interface(slice.router_id, slice.subnet_id) |
| 18 | client_driver.delete_subnet(slice.subnet_id) |
| 19 | client_driver.delete_router(slice.router_id) |
| 20 | client_driver.delete_network(slice.network_id) |
| 21 | driver.delete_tenant(slice.tenant_id) |
| 22 | # delete external route |
| 23 | subnet = None |
| 24 | subnets = client_driver.shell.quantum.list_subnets()['subnets'] |
| 25 | for snet in subnets: |
| 26 | if snet['id'] == slice.subnet_id: |
| 27 | subnet = snet |
| 28 | if subnet: |
| 29 | driver.delete_external_route(subnet) |
| 30 | slice_deployment.delete() |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 31 | slice.delete() |