blob: 33985fbd3cdb3453d00470d50e57ffbd81a5af6a [file] [log] [blame]
Tony Mackbdb188a2014-04-01 20:24:47 -04001from core.models import Slice, SliceDeployments, User
Tony Mack387a73f2013-09-18 07:59:14 -04002from observer.deleter import Deleter
Sapan Bhatiadbaf1932013-09-03 11:28:52 -04003
Tony Mack387a73f2013-09-18 07:59:14 -04004class SliceDeleter(Deleter):
Tony Mackf77f1402014-04-02 07:06:53 -04005 model='Slice'
Sapan Bhatiadbaf1932013-09-03 11:28:52 -04006
Tony Mackf77f1402014-04-02 07:06:53 -04007 def call(self, pk):
8 slice = Slice.objects.get(pk=pk)
Tony Mackbdb188a2014-04-01 20:24:47 -04009 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 Mack387a73f2013-09-18 07:59:14 -040031 slice.delete()