blob: 31d26fbb5548320d7273af3e4f60d44d8759c5de [file] [log] [blame]
Sapan Bhatia18e01e32014-11-11 21:43:31 -05001from core.models import Slice, SliceDeployment, User
Sapan Bhatia26d40bc2014-05-12 15:28:02 -04002from observer.deleter import Deleter
3from openstack.driver import OpenStackDriver
4
5class SliceDeploymentDeleter(Deleter):
Sapan Bhatia18e01e32014-11-11 21:43:31 -05006 model='SliceDeployment'
Sapan Bhatia26d40bc2014-05-12 15:28:02 -04007
8 def call(self, pk):
Sapan Bhatia18e01e32014-11-11 21:43:31 -05009 slice_deployment = SliceDeployment.objects.get(pk=pk)
Sapan Bhatia26d40bc2014-05-12 15:28:02 -040010 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()