Sapan Bhatia | 18e01e3 | 2014-11-11 21:43:31 -0500 | [diff] [blame] | 1 | from core.models import Slice, SliceDeployment, User |
Sapan Bhatia | 26d40bc | 2014-05-12 15:28:02 -0400 | [diff] [blame] | 2 | from observer.deleter import Deleter |
| 3 | from openstack.driver import OpenStackDriver |
| 4 | |
| 5 | class SliceDeploymentDeleter(Deleter): |
Sapan Bhatia | 18e01e3 | 2014-11-11 21:43:31 -0500 | [diff] [blame] | 6 | model='SliceDeployment' |
Sapan Bhatia | 26d40bc | 2014-05-12 15:28:02 -0400 | [diff] [blame] | 7 | |
| 8 | def call(self, pk): |
Sapan Bhatia | 18e01e3 | 2014-11-11 21:43:31 -0500 | [diff] [blame] | 9 | slice_deployment = SliceDeployment.objects.get(pk=pk) |
Sapan Bhatia | 26d40bc | 2014-05-12 15:28:02 -0400 | [diff] [blame] | 10 | user = User.objects.get(id=slice_deployment.slice.creator.id) |
| 11 | driver = OpenStackDriver().admin_driver(deployment=slice_deployment.deployment.name) |
| 12 | client_driver = driver.client_driver(caller=user, |
| 13 | tenant=slice_deployment.slice.name, |
| 14 | deployment=slice_deployment.deployment.name) |
| 15 | |
| 16 | if slice_deployment.router_id and slice_deployment.subnet_id: |
| 17 | client_driver.delete_router_interface(slice_deployment.router_id, slice_deployment.subnet_id) |
| 18 | if slice_deployment.subnet_id: |
| 19 | client_driver.delete_subnet(slice_deployment.subnet_id) |
| 20 | if slice_deployment.router_id: |
| 21 | client_driver.delete_router(slice_deployment.router_id) |
| 22 | if slice_deployment.network_id: |
| 23 | client_driver.delete_network(slice_deployment.network_id) |
| 24 | if slice_deployment.tenant_id: |
| 25 | driver.delete_tenant(slice_deployment.tenant_id) |
| 26 | # delete external route |
| 27 | #subnet = None |
| 28 | #subnets = client_driver.shell.quantum.list_subnets()['subnets'] |
| 29 | #for snet in subnets: |
| 30 | # if snet['id'] == slice_deployment.subnet_id: |
| 31 | # subnet = snet |
| 32 | #if subnet: |
| 33 | # driver.delete_external_route(subnet) |
| 34 | slice_deployment.delete() |