blob: 6f1aec027064e7eeb4268a60d71a2c35ca83db77 [file] [log] [blame]
Sapan Bhatia85e09082014-11-19 15:09:38 -05001from core.models import Slice, SliceDeployments, User
Sapan Bhatia26d40bc2014-05-12 15:28:02 -04002from observer.deleter import Deleter
3from openstack.driver import OpenStackDriver
4
Sapan Bhatia85e09082014-11-19 15:09:38 -05005class SliceDeploymentsDeleter(Deleter):
6 model='SliceDeployments'
Sapan Bhatia26d40bc2014-05-12 15:28:02 -04007
8 def call(self, pk):
Sapan Bhatia85e09082014-11-19 15:09:38 -05009 slice_deployment = SliceDeployments.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()