add new deleters, update existing deleters
diff --git a/planetstack/observer/deleters/network_deleter.py b/planetstack/observer/deleters/network_deleter.py
index 880b91c..0d21fda 100644
--- a/planetstack/observer/deleters/network_deleter.py
+++ b/planetstack/observer/deleters/network_deleter.py
@@ -1,17 +1,19 @@
-from core.models import Network
+from core.models import Network, NetworkDeployments
from observer.deleter import Deleter
+from observer.deleters.network_deployment_deleter import NetworkDeploymentDeleter
+from util.logger import Logger, logging
+
+logger = Logger(level=logging.INFO)
class NetworkDeleter(Deleter):
model='Network'
def call(self, pk):
network = Network.objects.get(pk=pk)
- if (network.router_id) and (network.subnet_id):
- self.driver.delete_router_interface(network.router_id, network.subnet_id)
- if network.subnet_id:
- self.driver.delete_subnet(network.subnet_id)
- if network.router_id:
- self.driver.delete_router(network.router_id)
- if network.network_id:
- self.driver.delete_network(network.network_id)
+ network_deployment_deleter = NetworkDeploymentDeleter()
+ for network_deployment in NetworkDeployments.objects.filter(network=network):
+ try:
+ network_deployment_deleter(network_deployment.id)
+ except:
+ logger.log_exc("Failed to delte network deployment %s" % network_deployment)
network.delete()
diff --git a/planetstack/observer/deleters/network_deployment_deleter.py b/planetstack/observer/deleters/network_deployment_deleter.py
new file mode 100644
index 0000000..72b10b2
--- /dev/null
+++ b/planetstack/observer/deleters/network_deployment_deleter.py
@@ -0,0 +1,21 @@
+from core.models import Network, NetworkDeployments
+from observer.deleter import Deleter
+from openstack.driver import OpenStackDriver
+
+class NetworkDeploymentDeleter(Deleter):
+ model='NetworkDeployment'
+
+ def call(self, pk):
+ network_deployment = NetworkDeployments.objects.get(pk=pk)
+ driver = OpenStackDriver().client_driver(caller=network_deployment.network.owner.creator,
+ tenant=network_deployment.network.owner.name,
+ deployment=network_deployment.deployment.name)
+ if (network_deployment.router_id) and (network_deployment.subnet_id):
+ driver.delete_router_interface(network_deployment.router_id, network_deployment.subnet_id)
+ if network_deployment.subnet_id:
+ driver.delete_subnet(network_deployment.subnet_id)
+ if network_deployment.router_id:
+ driver.delete_router(network_deployment.router_id)
+ if network_deployment.net_id:
+ driver.delete_network(network_deployment.net_id)
+ network_deployment.delete()
diff --git a/planetstack/observer/deleters/site_deleter.py b/planetstack/observer/deleters/site_deleter.py
index 17619c5..c97dee1 100644
--- a/planetstack/observer/deleters/site_deleter.py
+++ b/planetstack/observer/deleters/site_deleter.py
@@ -1,5 +1,6 @@
from core.models import Site, SiteDeployments
from observer.deleter import Deleter
+from observer.deleters.site_deployment_deleter import SiteDeploymentDeleter
class SiteDeleter(Deleter):
model='Site'
@@ -7,9 +8,7 @@
def call(self, pk):
site = Site.objects.get(pk=pk)
site_deployments = SiteDeployments.objects.filter(site=site)
+ site_deployment_deleter = SiteDeploymentDeleter()
for site_deployment in site_deployments:
- if site_deployment.tenant_id:
- driver = self.driver.admin_driver(deployment=site_deployment.deployment.name)
- driver.delete_tenant(site_deployment.tenant_id)
- site_deployment.delete()
+ site_deployment_deleter(site_deployment.id)
site.delete()
diff --git a/planetstack/observer/deleters/site_deployment_deleter.py b/planetstack/observer/deleters/site_deployment_deleter.py
new file mode 100644
index 0000000..fa97be2
--- /dev/null
+++ b/planetstack/observer/deleters/site_deployment_deleter.py
@@ -0,0 +1,12 @@
+from core.models import Site, SiteDeployments
+from observer.deleter import Deleter
+
+class SiteDeploymentDeleter(Deleter):
+ model='SiteDeployments'
+
+ def call(self, pk):
+ site_deployment = SiteDeployments.objects.get(pk=pk)
+ if site_deployment.tenant_id:
+ driver = self.driver.admin_driver(deployment=site_deployment.deployment.name)
+ driver.delete_tenant(site_deployment.tenant_id)
+ site_deployment.delete()
diff --git a/planetstack/observer/deleters/slice_deleter.py b/planetstack/observer/deleters/slice_deleter.py
index 33985fb..90b58c3 100644
--- a/planetstack/observer/deleters/slice_deleter.py
+++ b/planetstack/observer/deleters/slice_deleter.py
@@ -1,31 +1,19 @@
from core.models import Slice, SliceDeployments, User
from observer.deleter import Deleter
+from observer.deleters.slice_deployment_deleter import SliceDeploymentDeleter
+from util.logger import Logger, logging
+
+logger = Logger(level=logging.INFO)
class SliceDeleter(Deleter):
model='Slice'
def call(self, pk):
slice = Slice.objects.get(pk=pk)
- slice_deployments = SliceDeployments.objects.filter(slice=slice)
- for slice_deployment in slice_deployments:
- user = User.get(user=slice.creator)
- driver = self.driver.admin_driver(deployment=slice_deployment.deployment.name)
- client_driver = self.driver.client_driver(caller=user,
- tenant=slice.name,
- deployment=slice_deployment.deployment.name)
-
- client_driver.delete_router_interface(slice.router_id, slice.subnet_id)
- client_driver.delete_subnet(slice.subnet_id)
- client_driver.delete_router(slice.router_id)
- client_driver.delete_network(slice.network_id)
- driver.delete_tenant(slice.tenant_id)
- # delete external route
- subnet = None
- subnets = client_driver.shell.quantum.list_subnets()['subnets']
- for snet in subnets:
- if snet['id'] == slice.subnet_id:
- subnet = snet
- if subnet:
- driver.delete_external_route(subnet)
- slice_deployment.delete()
+ slice_deployment_deleter = SliceDeploymentDeleter()
+ for slice_deployment in SliceDeployments.objects.filter(slice=slice):
+ try:
+ slice_deployment_deleter(slice_deployment.id)
+ except:
+ logger.log_exc("Failed to delete slice_deployment %s" % slice_deployment)
slice.delete()
diff --git a/planetstack/observer/deleters/slice_deployment_deleter.py b/planetstack/observer/deleters/slice_deployment_deleter.py
new file mode 100644
index 0000000..33e0836
--- /dev/null
+++ b/planetstack/observer/deleters/slice_deployment_deleter.py
@@ -0,0 +1,34 @@
+from core.models import Slice, SliceDeployments, User
+from observer.deleter import Deleter
+from openstack.driver import OpenStackDriver
+
+class SliceDeploymentDeleter(Deleter):
+ model='SliceDeployments'
+
+ def call(self, pk):
+ slice_deployment = SliceDeployments.objects.get(pk=pk)
+ user = User.objects.get(id=slice_deployment.slice.creator.id)
+ driver = OpenStackDriver().admin_driver(deployment=slice_deployment.deployment.name)
+ client_driver = driver.client_driver(caller=user,
+ tenant=slice_deployment.slice.name,
+ deployment=slice_deployment.deployment.name)
+
+ if slice_deployment.router_id and slice_deployment.subnet_id:
+ client_driver.delete_router_interface(slice_deployment.router_id, slice_deployment.subnet_id)
+ if slice_deployment.subnet_id:
+ client_driver.delete_subnet(slice_deployment.subnet_id)
+ if slice_deployment.router_id:
+ client_driver.delete_router(slice_deployment.router_id)
+ if slice_deployment.network_id:
+ client_driver.delete_network(slice_deployment.network_id)
+ if slice_deployment.tenant_id:
+ driver.delete_tenant(slice_deployment.tenant_id)
+ # delete external route
+ #subnet = None
+ #subnets = client_driver.shell.quantum.list_subnets()['subnets']
+ #for snet in subnets:
+ # if snet['id'] == slice_deployment.subnet_id:
+ # subnet = snet
+ #if subnet:
+ # driver.delete_external_route(subnet)
+ slice_deployment.delete()
diff --git a/planetstack/observer/deleters/user_deleter.py b/planetstack/observer/deleters/user_deleter.py
index b82ea4a..3573f8d 100644
--- a/planetstack/observer/deleters/user_deleter.py
+++ b/planetstack/observer/deleters/user_deleter.py
@@ -1,15 +1,13 @@
from core.models import User, UserDeployments
from observer.deleter import Deleter
+from observer.deleters.user_deployment_deleter import UserDeploymentDeleter
class UserDeleter(Deleter):
model='User'
def call(self, pk):
user = User.objects.get(pk=pk)
- user_deployments = UserDeployments.objects.filter(user=user)
- for user_deployment in user_deployments:
- if user_deployment.user.kuser_id:
- driver = self.driver.admin_driver(deployment=user_deployment.deployment.name)
- driver.delete_user(user_deployment.user.kuser_id)
- user_deployment.delete()
+ user_deployment_deleter = UserDeploymentDeleter()
+ for user_deployment in UserDeployments.objects.filter(user=user):
+ user_deployment_deleter(user_deployment.id)
user.delete()
diff --git a/planetstack/observer/deleters/user_deployment_deleter.py b/planetstack/observer/deleters/user_deployment_deleter.py
new file mode 100644
index 0000000..49d349b
--- /dev/null
+++ b/planetstack/observer/deleters/user_deployment_deleter.py
@@ -0,0 +1,12 @@
+from core.models import User, UserDeployments
+from observer.deleter import Deleter
+
+class UserDeploymentDeleter(Deleter):
+ model='UserDeployment'
+
+ def call(self, pk):
+ user_deployment = UserDeployments.objects.get(pk=pk)
+ if user_deployment.user.kuser_id:
+ driver = self.driver.admin_driver(deployment=user_deployment.deployment.name)
+ driver.delete_user(user_deployment.user.kuser_id)
+ user_deployment.delete()