Sapan Bhatia | 26d40bc | 2014-05-12 15:28:02 -0400 | [diff] [blame] | 1 | from core.models import Network, NetworkDeployments |
| 2 | from observer.deleter import Deleter |
| 3 | from openstack.driver import OpenStackDriver |
| 4 | |
| 5 | class NetworkDeploymentDeleter(Deleter): |
| 6 | model='NetworkDeployment' |
| 7 | |
| 8 | def call(self, pk): |
| 9 | network_deployment = NetworkDeployments.objects.get(pk=pk) |
| 10 | driver = OpenStackDriver().client_driver(caller=network_deployment.network.owner.creator, |
| 11 | tenant=network_deployment.network.owner.name, |
| 12 | deployment=network_deployment.deployment.name) |
| 13 | if (network_deployment.router_id) and (network_deployment.subnet_id): |
| 14 | driver.delete_router_interface(network_deployment.router_id, network_deployment.subnet_id) |
| 15 | if network_deployment.subnet_id: |
| 16 | driver.delete_subnet(network_deployment.subnet_id) |
| 17 | if network_deployment.router_id: |
| 18 | driver.delete_router(network_deployment.router_id) |
| 19 | if network_deployment.net_id: |
| 20 | driver.delete_network(network_deployment.net_id) |
| 21 | network_deployment.delete() |