blob: 33e083620c9e47708c148579fef995383935f3e6 [file] [log] [blame]
Tony Mack79e78c82014-04-12 10:26:15 -04001from core.models import Slice, SliceDeployments, User
2from observer.deleter import Deleter
3from openstack.driver import OpenStackDriver
4
5class SliceDeploymentDeleter(Deleter):
6 model='SliceDeployments'
7
8 def call(self, pk):
9 slice_deployment = SliceDeployments.objects.get(pk=pk)
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()